3

I don't want the Add comment link displayed in the teaser. But the comment form should be displayed along with the content of the node which forms a part of a page.

Edit: I don't have access to the php code. I want to do it through the admin console. Is there a way I can uncheck "Add comment" from appearing in the teaser and instead appear in the full content node which forms a part of a page?

3

You can accomplish this with a custom module, as I found here https://drupal.org/node/1257788

Here is the code you'll need:

function MODULE_node_view_alter(&$build) {
  if ($build['#view_mode'] == 'teaser') {
    // remove "add comment" link from node teaser mode display
    unset($build['links']['comment']['#links']['comment-add']);
    // and if logged out this will cause another list item to appear, so let's get rid of that
    unset($build['links']['comment']['#links']['comment_forbidden']);
  }
}
1

In Drupal 7, this can be done in your theme with the THEME_preprocess_node() function, for placed inside your template.php file, or inside a custom module using HOOK_preprocess_node() function placed inside a custom module.

/**
 * Implements THEME_preprocess_node().
 */
function YOURTHEME_preprocess_node(&$vars) {

  if ($vars['node']->type == 'article') {
    // Remove Add comment link from teaser.
    unset($vars['content']['links']['comment']['#links']['comment-add']);

    // Remove login/register to comment link.
    unset($vars['content']['links']['comment']['#links']['comment_forbidden']);

    // Remove comment count for nodes with comments.
    unset($vars['content']['links']['comment']['#links']['comment-comments']);

  }
}

Note the above code is untested... I may not have the arrays of doom structured correctly there, but you should be able to figure out the right path to the variable to unset using print_r($vars['content'])

If you don't have access to your theme, the Hide Node Links contributed module may work, depending on your needs. It appears that the module disables all node links, not just the "Add Comment" link, and it does it for all view modes, not just the Teaser.

  • I should have also mentioned: I don't have access to the php code. I want to do it through the admin console. Is there a way I can uncheck 'Add Comment' from appearing in the teaser and instead appear on the full content node which forms a part of a page? – user23618 Nov 15 '13 at 8:53
  • I edited my response to respond to this followup. The Hide Node Links module might work to hide the 'Add Comment' link on both the teaser and the full page, but anything more complex will require coding. If you have the ability to install a contrib module, you more likely than not, also have the ability to edit the theme. – JamesWilson Nov 27 '13 at 16:49
  • Please take care when posting. and does not work in PHP. Use ' character. – Mołot Apr 25 '14 at 14:17
0

This works for me, including in template.php. I have to include the return.

function MYTHEME_node_view_alter(&$build){
    if ($build['#view_mode'] == 'teaser')
    {
        // remove "add comment" link from node teaser mode display
        unset($build['links']['comment']['#links']['comment-add']);
        // and if logged out this will cause another list item to appear, so let's get rid of that
        unset($build['links']['comment']['#links']['comment_forbidden']);
    }
}
function MYTHEME_links($links) {
    return theme_links($links);
}
0

If you don't have access to PHP code, you can do it through the admin console if you install and enable a module named Fix teaserlinks.

The “Fix teaserlinks” module is a simple module that may be used to mange the visibility of the links that appear below teasers (i.e. “Add new comment”, “Log in or register to post comments”, “Read more”).

There are versions for both Drupal 7 and Drupal 8.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.