Theming node's links in Drupal 6
By default, the node links in the blog page con开发者_JS百科tains blog_usernames_blog
(admin's blog), comment_add
(Add new comment) and node_read_more
(Read more).
I need to get rid of the first 2 of them, and to change the text in node_read_more.
I created a function named $themenamepreprocess_node
into template.php in my theme, with this content:
function mytheme_preprocess_node(&$vars, $hook){
$node = $vars['node'];
//blog node, not in full node page
if($vars['node']->type == 'blog' AND !$vars['page']){
$vars['node']->links['node_read_more']['title'] = t('My custom read more here');
unset($vars['node']->links['blog_usernames_blog']);
unset($vars['node']->links['comment_add']);
}
//debug:
echo "<!-- DEBUG\n";
print_r($vars['node']->links);
echo "\n-->";
}
But it doesnt work; when i print the $vars['node']->links
in the end of the functions, the links array is exactly as i want it; but when the page is rendered, the old default links are showed.
Why? How can i theme the node links just for some content-type and only in the node list page, with theming functions?
p.s: i cleared the cache and the theme registry before every try ;)
First: you should test on $hook, else this preprocess function will be called on each and every place. It will bring your site down, even if you run a small site on a large server.
Second: if the print_r, prints the correct links, then for sure the code /is/ ran, no need to worry about the theme registry.
Now, you probably are looking at the wrong theme-hook. theme_links is what you will want. http://api.drupal.org/api/function/theme_links/5
function mytheme_preprocess_links(&$vars, $hook){
if ($hook == 'links') {
var_dump($vars);
unset($vars['links']['blog_usernames_blog']);
}
}
精彩评论