views:

144

answers:

1

By default, the node links in the blog page contains 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 ;)

+1  A: 

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']);
    }
}
berkes
Thanks for the suggestions, they are really appreciated, im new to drupal.. but did you wrote the example wrong? i see your example is using theme_preprocess_node instead of theme_link, that you pointed out
DaNieL
Sorry. Indeed, I wrote the function wrong. Edited it.
berkes
mmh... at api.drupal.org there is no `theme_preprocess_links`, and neither any `*_preprocess_links`... did you mean `hook_link_alter` ?
DaNieL
preprocess_* is a "magic" function: for theme_foo, it is yourthemename_preprocess_foo()
berkes