Community Documentation

Customize node links

Last updated March 10, 2010. Created by Kami Petersen on March 10, 2010.
Log in to edit this page.

Description

This illustrates how to change the output of an individual link in the node links area on a theme basis.

Example 1

This shows how to change the comment count string from "5 comments" to simply "5". I like to use this format on top of a background image of a speech bubble.

Add something like this to your theme's template.php file:

<?php
YOUR_THEME_NAME_preprocess_node
(&$vars) {
//  drupal_set_message('<pre>' . print_r(get_defined_vars(),TRUE) . '</pre>'); // print what variables are available
//  drupal_set_message('<pre>' . print_r($vars['node']->links, TRUE . '</pre>')); // print what links are available

  // some sanity checks
 
if ($vars['is_front']) {
    if (
$vars['node']->comment) {
      if (
user_access('access comments')) {
       
// get the comment count
       
$all = comment_num_all($vars['node']->nid);
        if (
$all) {
          if (
$vars['node']->links[comment_comments]['title']) {
           
$vars['node']->links[comment_comments]['title'] = $all;
          }
        }
      }
    }
  }
 
// update the themed links
 
$vars['links'] = theme_links($vars['node']->links, array('class' => 'links inline'));
}
?>

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Designers/themers

Theming Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.