简体   繁体   中英

Drupal 7, trying to “theme” the node links i.e. “Add new Comment” “Read More” etc

I'm spending more and more time here, and constantly wishing Drupal was easier to understand then I'm finding it, oh well:)

so todays question is, I'm trying to remove the "2 comment" and "1 new comment" links from a node in Teaser view. I do however want to keep the "Read More" and "Add new Comment" links.

So I've found all this is stored in "print render($content['links']);"

I have also discovered that "Read More" can be requested using "print render($content['links']['node']);" and all 3 comment links can be pulled out using "print render($content['links']['comment']);"

What I cannot work out is how to break down the Comment part so I can strip out the 2 I dont need.

anyone know?

thanks in advance.

To expand on what @coleopterist said, the following worked well for me:

mytheme_node_view_alter(&$build) {
    if ($build['#view_mode'] == 'teaser') {
        $build['links']['node']['#links']['node-readmore']['title'] = t('Read More »');
    }
}

The functions that you are looking for are probably hook_node_view_alter and hook_comment_view_alter .

FYI, a quick fix is also possible via CSS where you can simply hide the offending DIV.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM