Can anyone tell me how to add list classes to quick tabs tab lists in drupal 7. it seems that in drupal 6, first and last classes are added by default, but in drupal 7, only the active class is used. Can anyone please help?

Comments

jeremycaldwell’s picture

I actually got this working the other day as I needed to have classes on my tabs so I could style them differently. So now I have class names like "tab-1" and "tab-2" so it makes things much easier than using the nth selector in CSS3 and finding workarounds for IE.

Anyways here is the code. Add it to your theme's template.php and in this case I was using the jQuery UI tabs style for my Quicktabs.

/**
 * Theme function to output tablinks for jQuery UI style tabs.
 *
 * @ingroup themeable
 */
function YOURTHEME_qt_ui_tabs_tabset($vars) {
  $output = '<ul>';
  foreach ($vars['tabset']['tablinks'] as $i => $tab) {
    if (is_array($tab)) {
      $output .= '<li class="tab-' . $i . '">'. drupal_render($tab) .'</li>';
    }
  }
  $output .= '</ul>';
  return $output;
}

Be sure to replace "YOURTHEME" with your theme's name and clear the cache on the Performance page so it picks up these changes. That should then add the class names to your tabs.

bolo79’s picture

Thanks!

somalinet’s picture

StatusFileSize
new1.28 KB
new1.3 KB

Hello,
drupal7/quicktabs 7.x-3.0: the first and last tab classes are missing when using quicktabs renderer. excel style looks broken. No problem with drupal6. My quick remedy was to add a couple of lines to theme_qt_quicktabs_tabset function in quicktabs.module

graylawry’s picture

Version: 7.x-3.x-dev » 7.x-3.0
Assigned: Unassigned » bolo79
Status: Needs review » Active

Thanks for this. I used this to add a span and the class of "last" on the last tab.

//Adds Spans Around Quick Tabs Anchors & Adds the class last to the last link. 

function YOURTHEME_qt_quicktabs_tabset($vars) {
  $indexMax = count($vars['tabset']['tablinks']);
  $mycount = 0;

  $output = '<ul class="quicktabs-tabs quicktabs-style-'. $vars['tabset']['#options']['style'] .'">';
  foreach ($vars['tabset']['tablinks'] as $i => $tab) {
  	$mycount++;
    if (is_array($tab)) {
    	if ($mycount < $indexMax){
    	   $active = $i == $vars['tabset']['#options']['active'] ? ' class="active"' : '';
           $output .= '<li'. $active .'>'. drupal_render($tab) . '<span></span>' .'</li>'; /* Spans added on this line */
    	 } else {
    	 $output .= '<li'. ' class="last"' .'>'. drupal_render($tab) . '<span></span>' .'</li>';
    	 }
       }
  }
  $output .= '</ul>';
  return $output;
}
awolfey’s picture

Version: 7.x-3.0 » 7.x-3.x-dev
Assigned: bolo79 » Unassigned
Status: Active » Needs review
StatusFileSize
new1.14 KB

Here's a patch that changes function theme_qt_quicktabs_tabset() to use theme_item_list(), which adds first and last classes.

awolfey’s picture

StatusFileSize
new1.15 KB

Sorry, use this one.

brycesenz’s picture

The patch in #6 worked beautifully for me.

katbailey’s picture

Version: 7.x-3.0 » 7.x-3.x-dev
Assigned: bolo79 » Unassigned
Status: Active » Needs review

Really sorry for the delay on this. Committed (with just a small change to initialize the $variables array for readability): http://drupalcode.org/project/quicktabs.git/commit/5831140

katbailey’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Specified problem with quicktabs in Drupal 7.