/ Published in: PHP
URL: http://api.drupal.org/api/function/theme_links/5
Place the first function, phptemplatelinks() in your template.php file. Alternatively (and IMO better) is to name the function yourthemenamelinks() where yourthemename is the name of your theme.
From here on, you can add theme functions like yourthemenamelinkscommentadd(), whom will render the specific links with the commentadd class.
Expand |
Embed | Plain Text
/** * 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"; }
You need to login to post a comment.
