Changing the delimiter on primary/secondary links

Note: See http://drupal.org/node/112761 for working with Drupal 5's primary links.

Drupal 6.9

Thanks to dman for a nudge in the right direction via his forum comment.

Copy and paste the theme_links function from theme.inc to your template.php file. change the name of the function to YOURTHEME_links where YOURTHEME is the name of your theme.

Add the following code snippet on the second line of the function, after the "$output=' ';"

<?php
// | delimiter added here.
   
if($attributes['class'] == 'links secondary-links') {
   
$linklist = array();
    foreach ((array)
$links as $key => $link) {
       
$linklist[] = l($link['title'], $link['href'], $link);
    }
   
// Return the links joined by a '|' character
   
return join(' | ', $linklist);
?>

  }

As it is currently setup the secondary links will have the delimiter.

Next go to your page.tpl.php file and insert the following code into where you want the links to show up.

<?php
if(isset($secondary_links)){
        print
YOURTHEME_links($secondary_links, array('class' => 'links secondary-links'));
   }
?>

Drupal 4.7

Locate:

<?php
print theme('links', $primary_links)
?>

To add a semi-colon as your deliminater change the code to:

<?php
print theme('links', $primary_links, ' : ')
?>

Drupal 4.5 and 4.6

This snippet allows you to specify a delimiter for your primary or secondary links.

Thanks to bumathan for this snippet.

Primary links snippet:

<div id="navigation">
<?php if (is_array($primary_links)) : ?>
<ul id="main-nav">
<?php
$primary_link_delimiter
= '|'// Change this to what you want the links seperated by
$primary_delimiter = '</li>' . $primary_link_delimiter . '<li>';
print
'<li>' . implode($primary_delimiter, $primary_links) . '</li>';
?>

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

Secondary links snippet:

<div id="navigation">
<?php if (is_array($secondary_links)) : ?>
<ul id="main-nav">
<?php
$secondary_link_delimiter
= '|'// Change this to what you want the links seperated by
$secondary_delimiter = '</li>' . $secondary_link_delimiter . '<li>';
print
'</li>' . implode($secondary_delimiter, $secondary_links) . '</li>';
?>

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

Tips/tricks

Below is an example of the syntax used to change the delimiter to an image, instead of a character (thanks to pwolanin for this tip):

$primary_link_delimiter = '<img src="/path_to_image/myimage.gif">';

Delimiter for D6 menu not working for me

defsince78 - October 29, 2009 - 01:49

I tried the this for D6.14 using Zen theme but I can't get to work. I get a php error when I insert the code into the template.php file and I lose li tags. Can anyone help with this issue?

Everything I'm not, makes me everything I am

 
 

Drupal is a registered trademark of Dries Buytaert.