theme_links builds a list of links which marks and adds the 'active' class to the active link. The problem is, this class really needs to be added, not to the [a]..[/a] tag but rather to the surrounding [li] .. [/li] tag in order to apply the sliding door graphics for the active tab.

I've looked at overriding the theme_links code and it does not seem to be responsible for adding the 'active' class to the link.

Has anyone created a sliding door tabs (with active tab marked) in 5.x?

Thanks,

Chadj

Comments

chadj’s picture

I copied the theme_links code over to my template.php theme file and added a line of code to insert the 'active' class into the list item (li) here's the code in case anyone wants to do the same:

<?php
/**
* Catch the theme_links function  
*/
function phptemplate_links($links, $attributes) {
 $output = '';

  if (count($links) > 0) {
    $output = '<ul'. drupal_attributes($attributes) .'>';

    $num_links = count($links);
    $i = 1;

    foreach ($links as $key => $link) { 
      $class = '';

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

// this line added to allow for sliding door active tab
if(stristr($link['attributes']['class'],'active')) $class .= ' active';

      // 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 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;
} 


?>

radioactivesmartie’s picture

Do I need to change anything else to get this to work? My base code is

<div id="navigation">
<?php if (is_array($primary_links)) : ?> 
<ul id="main-nav">
<?php foreach ($primary_links as $link): ?>
<li><?php

$href = $link['href'] == "<front>" ? base_path() : base_path() . $link['href'];
print "<a href='" . $href . "'>" . $link['title'] . "</a>";

?></li>

<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>