You are here

function theme_links in Drupal 5

Same name and namespace in other branches
  1. 4 includes/theme.inc \theme_links()
  2. 6 includes/theme.inc \theme_links()
  3. 7 includes/theme.inc \theme_links()

Return a themed set of links.

Parameters

$links: A keyed array of links to be themed.

$attributes: A keyed array of attributes

Return value

A string containing an unordered list of links.

Related topics

13 theme calls to theme_links()
aggregator_page_categories in modules/aggregator/aggregator.module
Menu callback; displays all the categories used by the aggregator.
aggregator_page_sources in modules/aggregator/aggregator.module
Menu callback; displays all the feeds used by the aggregator.
chameleon_comment in themes/chameleon/chameleon.theme
chameleon_node in themes/chameleon/chameleon.theme
chameleon_page in themes/chameleon/chameleon.theme

... See full list

File

includes/theme.inc, line 542
The theme system, which controls the output of Drupal.

Code

function theme_links($links, $attributes = array(
  'class' => 'links',
)) {
  $output = '';
  if (count($links) > 0) {
    $output = '<ul' . drupal_attributes($attributes) . '>';
    $num_links = count($links);
    $i = 1;
    foreach ($links as $key => $link) {
      $class = $key;

      // Automatically add a class to each link and also to each LI
      if (isset($link['attributes']) && isset($link['attributes']['class'])) {
        $link['attributes']['class'] .= ' ' . $key;
      }
      else {
        $link['attributes']['class'] = $key;
      }

      // Add first and last classes to the list of links to help out themers.
      $extra_class = '';
      if ($i == 1) {
        $extra_class .= 'first ';
      }
      if ($i == $num_links) {
        $extra_class .= 'last ';
      }
      $output .= '<li ' . drupal_attributes(array(
        'class' => $extra_class . $class,
      )) . '>';

      // Is the title HTML?
      $html = isset($link['html']) && $link['html'];

      // Initialize fragment and query variables.
      $link['query'] = isset($link['query']) ? $link['query'] : NULL;
      $link['fragment'] = isset($link['fragment']) ? $link['fragment'] : NULL;
      if (isset($link['href'])) {
        $output .= l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html);
      }
      else {
        if ($link['title']) {

          //Some links are actually not links, but we wrap these in <span> for adding title and class attributes
          if (!$html) {
            $link['title'] = check_plain($link['title']);
          }
          $output .= '<span' . drupal_attributes($link['attributes']) . '>' . $link['title'] . '</span>';
        }
      }
      $i++;
      $output .= "</li>\n";
    }
    $output .= '</ul>';
  }
  return $output;
}