Customize links menu in Drupal

Tested on: Zen theme, Drupal 5.7

  1. Copy function theme_links from includes/themes.inc
  2. Paste it into your template.php
  3. Rename it in theme_primarylinks (or anything you want)
  4. In your page.tpl.php, change
    1. print theme(‘links’, $primary_links);
    2. to print theme(‘primarylinks’, $primary_links);
  5. Apply some changes to theme_primarylinks to customize your primary links.

According to theme manual, for any first argument passed to theme function a theme_functionname function is called.

Advertisements

6 thoughts on “Customize links menu in Drupal

  1. Diego Cortassa

    Thanks, Great tip!
    I’m using this technique in a site I’m developing on Drupal5.

    I found a simple way to change image depending on the active link too, here is a piece of my code form “theme_primarylinks” function (I ave a PrimaryLink folder in my images in there I have a menuname.png image and a menunameActive.png image):

    ———————————————
    // 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’])) {
    $linkactive = “”;
    // should this button be active?
    if(substr($link[‘attributes’][‘class’], -6) == “active” ) { $linkactive = “Active”;}
    // if an active image exixts use it!
    if(file_exists(“/opt/lampp/htdocs/” . path_to_subtheme() . “/images/PrimaryLinks/” . $link[‘title’] . $linkactive . “.png”)) {

    $output .= l(“”,
    $link[‘href’], $link[‘attributes’], $link[‘query’], $link[‘fragment’], FALSE, $html = TRUE);

    }
    else {
    $output .= l($link[‘title’], $link[‘href’], $link[‘attributes’], $link[‘query’], $link[‘fragment’], FALSE, $html);
    }
    }

    ————————————————————-

    Reply
  2. my discovery

    How about a video on how to turn the primary links to an image. Gosh, I’ve been hours looking for a step by step tutorial. I feel so frustrated =( I’m not that versed in PHP, whew.. help? anyone.. at least just reference. =)

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s