/ Published in: PHP
                    
                                        
Place the first function, phptemplate_links() in your template.php file. Alternatively (and IMO better) is to name the function your_theme_name_links() where your_theme_name is the name of your theme.
From here on, you can add theme functions like your_theme_name_links_comment_add(), whom will render the specific links with the comment_add class.
                From here on, you can add theme functions like your_theme_name_links_comment_add(), whom will render the specific links with the comment_add class.
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
/**
* Return a themed set of links.
*
* @param $links
* A keyed array of links to be themed.
* @param $attributes
* A keyed array of attributes
* @return
* A string containing an unordered list of links.
*/
$output = '';
$i = 1;
$items_str = '';
foreach ($links as $key => $link) {
$class = '';
// Automatically add a class to each link and also to each LI
$link['attributes']['class'] .= ' ' . $key;
$class = $key;
}
else {
$link['attributes']['class'] = $key;
$class = $key;
}
// Add first and last classes to the list of links to help out themers.
$extra_class = '';
if ($i == 1) {
$extra_class .= 'first ';
}
if ($i == $num_links) {
$extra_class .= 'last ';
}
// Is the title HTML?
// Initialize fragment and query variables.
//Check if we have a link, for sometimes we need to output just a splain string.
//A class can only contain spaces, hyphens or underscores. Translate these to underscores.
//dpm($func_class);
//First, see if we have a theme function for this class
if (!empty($func_class) && ($function = theme_get_function('links_'. $func_class))) { //then, look for a theme function based on the class.
dpm($function);
$items_str .= theme('links_'. $func_class, $link);
}
else { //If no specific function was found, fall back to a default.
$items_str .= '<li class="'. $extra_class . $class .'">';
$items_str .= l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html); $items_str .= "</li>\n";
}
}
else if ($link['title']) {
//Some links are actually not links, but we wrap these in <span> for adding title and class attributes
if (!$html) {
$link['title'] = check_plain($link['title']);
}
$items_str .= '<span'. drupal_attributes($link['attributes']) .'>'. $link['title'] .'</span>';
}
$i++;
}
$output = '<ul'. drupal_attributes($attributes) .'>'. $items_str .'</ul>';
}
return $output;
}
/**
* Theme callbakc from theme_links, renders the comment_add link
**/
function phptemplate_links_comment_add($ink) {
$output = '"<li class="'. $extra_class . $class .'">';
$output .= l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html);
$output .= "</li>\n";
}
URL: http://api.drupal.org/api/function/theme_links/5
Comments
 Subscribe to comments
                    Subscribe to comments
                
                