Customizing how links ($links) are displayed in your pages

Last modified: June 20, 2009 - 18:04

description

This describes how to override the default layout for links when using phptemplate based themes (for Drupal 4.6 and 4.7). Please refer to the changes in theme_links so these snippets will work with Drupal 5.x and later.

Step 1 of 2

In a text editor like notepad.exe, create a file called template.php using the the following snippet. If you already have a template.php file, simply add this snippet to your existing one.

<?php
function phptemplate_links($links = array(), $delimiter = ' | ') {
 
/**
* catches the theme_links function and calls back a link.tpl.php file to determine the layout
*/
 
return _phptemplate_callback('links', array('links' => $links, 'delimiter' => $delimiter));
}
?>

Step 2 of 2

The template.php snippet catches the default theme_links layout before it's displayed and looks in the same folder for a links.tpl.php file which determines the new layout.

A very simple/shortened example of a links.tpl.php file maybe illustrated as follows....

Using a text editor like notepad.exe or other, paste the following snippet and save as links.tpl.php. Upload your new links.tpl.php file to your active theme folder.

<?php

 
/**
* to change the delimiter, just modify the $delimiter value
* Add in other fixed links to the link array by adding something like
* $links[] = l('link text', 'link path');
*
*/

$delimiter = "|";
// Display the left cap of the 'button bar'
print "[";
$link_count = count($links);
$current = 1;
foreach (
$links as $lnk ) {
       
// Print the link
   
print $lnk;
       
// Only print the delimiter if not the last link
   
if ( $current < $link_count ) {
        print
$delimiter;
    }
   
$current++;
}
// Display the right cap of the 'button bar'
print "]";
?>

 
 

Drupal is a registered trademark of Dries Buytaert.