3

How can show only "read more" link in node's teaser, and remove or unset other links like "add new comments" or "2 Comments" at the end of a node teaser?

4

There are two ways to do this:

  1. Through PHP. This is the correct way. The code below would go in your theme's .theme file.

    function YOUR_THEME_preprocess_links(&$variables) {
      // Determine which links should be removed. These are CSS classes, because
      // they are used as keys in the $variables['links'] array.
      $links_to_remove = array(
        // X comments link.
        'comment-comments',
        // X new comments.
        'comment-new-comments',
        // Add new comment.
        'comment-add',
      );
      // Loop through the links and remove them.
      foreach ($variables['links'] as $css_class => $link) {
        if (in_array($css_class, $links_to_remove)) {
          unset($variables['links'][$css_class]);
        }
      }
    }
    
  2. Through CSS. This is not the best way, but is faster:

    .your-node-selector .node__links li.comment-comments,
    .your-node-selector .node__links li.comment-new-comments,
    .your-node-selector .node__links li.comment-add {
      display: none;
    }
    
  • Thank you very much for your kindness, My problem was solved. – Mojtaba Reyhani Feb 28 '16 at 10:12
1

If I remember correctly, Drupal 8 uses views to display teasers.

If that is the case, all you have to do is edit the teaser view and change Content: Teaser to Content: Fields and then just add the fields you want. Basically, you can create your own custom teaser.

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.