To add an image/icon to a link, you can use simple CSS. This CSS will add an icon to the "Add Comment" link, but the same could be done for other links as well (li.comment_delete, li.comment_edit, etc).
ul.links > li.comment_add > a {
background: url(PATH TO IMAGE) no-repeat;
padding-left: 20px; /* Change to compensate for size of image */
}
To add the number of comments on a node you can use the function comment_num_all($node->nid)
. For instance if you would like to add the number of comments to the "Add comment" link, you could add a hidden DIV to the node.tpl.php (or each content type template) and jQuery to edit the link text:
<div id="num-comments" style="display:none;"><?php print comment_num_all($node->nid); ?></div>
jQuery:
$('ul.links > li.comment_add > a').text('Add new comment (' + $('#num-comments').text() + ')');
This is not the most elegant solution, but it works. If you want to use theme_links()
I think you would have to create a custom module.
EDIT:
Another option is to create a custom module. This does not use theme_links()
, but hook_link_alter()
instead. This is a small example module to change the title of the "Add new comment" link, add an icon and include the number of current comments attached to the node: (Replace every instance of MYMODULE_NAME with the name you choose for the module)
STEP 1: Create a file called MYMODULE_NAME.info and add:
name = "MYMODULE_NAME"
description = "Change the appearance of links that appear on nodes"
core = 6.x
STEP 2: Create file called MYMODULE_NAME.module and add:
<?php
/**
* Implementation of hook_link_alter
*/
function MYMODULE_NAME_link_alter(&$links, $node){
if (!empty($links['comment_add'])) {
// Get number of comments for node
$num_comments = db_result(db_query('
SELECT comment_count
FROM {node_comment_statistics}
WHERE nid = %d
', $node->nid));
// Set "Add new comment" link text
$links['comment_add']['title'] = '<img src="PATH TO ICON"/> ADD COMMENT TEXT (' . $num_comments . ')';
// Allow HTML in the link text
$links['comment_add']['html'] = TRUE;
}
}
STEP 3: Put these files in a folder called MYMODULE_NAME, place the folder in sites/all/modules, and enable the module
EDIT: To find array keys:
in your node.tpl.php (or any other node template) you can add <?php print_r($node->links); ?>
. This will show you all of the link info to be displayed in the node, and the keys of the main array are what you would use in my module. You can also try using Firebug/Chrome Dev Tools, etc to look at the class of the list item containing the link (ie ul.links > li.comment_add). I believe when the links are constructed, Drupal uses the array key as a class for the link.