I'm having sort of an issue...I'm currently customizing a theme and creating a css nav bar from the primary links. The thing is, the nav bar is too short (horizontally) and I can't add any more padding otherwise it'll overflow. So...I'm trying to assign individual classes to the primary links

  • matching the name of the title of the
  • .

    I'm assuming there's a function somewhere like:

    while (whatever){
    print "

  • Link Name
  • "
    }

    But I cant' seem to find it, can someone help me out here?

    I'm trying to modify that function to read:

    while (whatever){
    print "

    "
    }

    Comments

    CWolff’s picture

    Gah, what I meant was:

    I'm having sort of an issue...I'm currently customizing a theme and creating a css nav bar from the primary links. The thing is, the nav bar is too short (horizontally) and I can't add any more padding otherwise it'll overflow. So...I'm trying to assign individual classes to the primary links matching the name of the title of the li tag

    I'm assuming there's a function somewhere like:

    while (whatever){
    print "<li> <a href = "link name">Link name</a>"
    }
    

    But I cant' seem to find it, can someone help me out here?

    I'm trying to modify that function to read:

    while (whatever){
    print " <li class = "link name"> <a href = "link name">Link name</a>
    }
    

    ------------------------
    Cassandra Wolff
    PHP Developer
    Gaiam Inc.
    Direct: 303-222-3676
    cassandra.wolff@gaiam.com

    gpk’s picture

    Check your page.tpl.php. It probably includes something like print theme('links', $primary_links, array('class' => 'links primary-links')). Check theme_links on http://api.drupal.org; this function is used to "theme" all links which are handled as such by Drupal. Possibly also have a look at theme_menu_links.

    You may then want to create your own function phptemplate_theme_primary_links say in template.php based on the above. In page.tpl.php you can call directly, or via theme('primary_links', ...).

    There may be neater ways of doing this (I find this part of the menu/themeing system a bit confused/ing, partly because themeing of menus in blocks and across the top of the page is handled differently) but this should get you started.

    gpk
    ----
    www.alexoria.co.uk

    CWolff’s picture

    Thank you GPK!

    You were right, the function was actually declared as theme_menu_links in menu.inc. I decided not to just override the function since this template is exclusive to only this project for my company. Instead, I just added the class and $link['title'] like so:

    function theme_menu_links($links) {
      if (!count($links)) {
        return '';
      }
      $level_tmp = explode('-', key($links));
      $level = $level_tmp[0];
      $output = "<ul class=\"links-$level\">\n";
      foreach ($links as $index => $link) {
        $output .= '<li class = "'.$link['title'].'"';
        if (stristr($index, 'active')) {
          $output .= ' class="active"';
        }
        $output .= ">". l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment']) ."</li>\n";
      }
      $output .= '</ul>';
    
      return $output;
    }
    

    Thanks again, you were tons of help.

    ------------------------
    Cassandra Wolff
    PHP Developer
    Gaiam Inc.
    Direct: 303-222-3676
    cassandra.wolff@gaiam.com

    gpk’s picture

    You might still want to put rename your final function to phptemplate_menu_links() and put it in template.php. That way, if you need to upgrade Drupal in the future, you won't have to re-customise menu.inc again (i.e. avoid hacking core if possible)

    gpk
    ----
    www.alexoria.co.uk

    CWolff’s picture

    Thanks GPK, I went ahead and did that because you're right. It would be a pain to have to go through all the core files if my company decides to do an upgrade or screws something up.

    ------------------------
    Cassandra Wolff
    PHP Developer
    Gaiam Inc.
    Direct: 303-222-3676
    cassandra.wolff@gaiam.com

    gpk’s picture

    :-)

    gpk
    ----
    www.alexoria.co.uk