Styling or modifying drupal primary and secondary tabs like drupal.org

If you want your drupal website’s primary and secondary tabs in same style like drupal.org have in “bluebeach” theme. (See the below graphic.)

Durpal styled tab

Drupal styled tab

Then you have to create a wrapper for tabs so you can put the rounded corner images on both side of tabs. like this

<span class=”a”><span class=”b”>Tab Title</span></span>

But the default “garland” theme does not provide this wrapper. So, you have to put this wrapper by customizing theme. Here I am just illustrating the code that you need to create wrapper around the tabs. After that you need to put the necessary style in your CSS files.

You need to change the “theme_menu_item_link()” to put these wrappers in tab. I am using the code of Drupal 6.9 in this example but I think this approach will work in all versions of Drupal by little tweak.

Existing code:

<?php
	function theme_menu_item_link($link) {
		if (empty($link['localized_options'])) {
			$link['localized_options'] = array();
		}
 
                return l($link['title'], $link['href'], $link['localized_options']);
	}
?>

New code (With changes required)

<?php
	function theme_menu_item_link($link) {
		if (empty($link['localized_options'])) {
			$link['localized_options'] = array();
		}
               if ($link['tab']) {
			$link['title'] =<span class=”a”><span class=”b”>. $link['title'] .</span></span>;
			$link['localized_options'] = $link['localized_options'] + array(’html’ => TRUE);
	       }
 
               return l($link['title'], $link['href'], $link['localized_options']);
        }
?>

, ,


  1. #1 by RaiulBaztepo - March 31st, 2009 at 11:54

    Hello!
    Very Interesting post! Thank you for such interesting resource!
    PS: Sorry for my bad english, I’v just started to learn this language ;)
    See you!
    Your, Raiul Baztepo

  2. #2 by vikl - July 1st, 2009 at 23:07

    if ($link['tab'])

    what do you mean by ['tab'] –> is this a name of a menu or what is it?

  3. #3 by admin - July 2nd, 2009 at 10:37

    @ vikl
    ['tab'] is a variable is $link array which Drupal creates to identify that this menu is a tab. Tabs are secondary menus in Drupal. Like I am showing in above image.

  4. #4 by tom - November 12th, 2009 at 04:30

    hi, great article!
    i am bad with coding – any ideas how i could put this into my themes code for my primary links
    code is below for the primary links in page.tpl.php

    ‘links’, ‘id’ => ‘subnavlist’)) ?>
    ‘links’, ‘id’ => ‘navlist’)) ?>

  5. #5 by aleksey - December 14th, 2010 at 15:53

    hello weii interesting post.
    unfortunately this solution not work for me and i don’t know whie
    i paste function _menu_item_link() in file template.php but it`s not work function not captured control
    please help

  6. #6 by aleksey - December 15th, 2010 at 10:30

    i find another metod
    using
    function theme_menu_local_task($link, $active = FALSE) {
    return ” . $link . “\n”;
    }
    this work

    function theme_menu_local_task($link, $active = FALSE) {
    return ” . $link . “\n”;
    }

  7. #7 by srinivasan - September 27th, 2011 at 14:10

    hi am new to drupal. i want to colour the tabs in my custom module.plz guide me

(will not be published)

 


Submit Comment
Subscribe to comments feed
  1. No trackbacks yet.