I want to theme the "Add Comment" and "Comments" links that are shown on a node that has comments enabled. I know there's theme()
and theme_links()
that can help with this, but I'm not sure how to use them. I'm pretty sure I want theme_links()
, since I'm after links in this case. But how to I get the comment links specifically? I don't want to theme all links, just the ones on the comments. If it helps, my goal is to add an image next to each of these links. Also, next to "Comments" I want to include the number of comments posted.
To clarify, I want to theme the links that appear on the Node, not the links that appear on the Comments themselves.
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).
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:jQuery:
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()
, buthook_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:
STEP 2: Create file called MYMODULE_NAME.module and add:
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.