User login

Remove "Add comment" links from teasers

See and report to:

How to disable "Add new comment" at teaser part, but "Read more" remains
http://drupal.org/node/151648

Hi Brian,

So the Drupal user interface wasn't enough? You had to make a custom node template? It took us a few months to notice the new options for displaying fields, but now we use it a lot instead of node-TYPE.tpl.php files. And I'd be interested what in that post needed updating for Drupal 6!

Well, if you're using teasers on the front page, or any Views listing page, you should get pretty much exactly the behavior your asking for, see for instance Drupal.org homepage:

http://drupal.org/node

with links for:

Comments Read more

So does setting your View (you are using a view?) on the front page to teaser doesn't do it? Actually, a View listing with Full Nodes really should work that way too. How exactly are you pulling up the node that's showing comments rather than a link?

Oh, OK, I see the Add comment link on a Drupal 6 site.

There are ways to take over the display of the links.

From a custom module, use an implementation of this hook function:
http://api.drupal.org/api/function/hook_link_alter/6

described a bit in the top part of this post:
http://agaricdesign.com/note/override-taxonomy/term-style-links-custom-module-owned-vocabulary

If you don't want to make a module (a folder, a .info file, and a .module file) there's an arguably quicker and certainly dirtier option. That code passes through the theme_links function (which you can verify by installing http://drupal.org/project/devel and enabling the Theme Developer module), so you can catch and override it by implementing the function in your theme in your own way. You'll need to copy the entire function from:

http://api.drupal.org/api/function/theme_links/6

So to properly override it in "YOURTHEMENAME_links" or, so you can reuse your code more easily, "phptemplate_links" in your template.php file. You'll want to copy the whole function because yeah, this links theming function will be used in other places and you don't want to break how any of that works.

Throw a
drupal_set_message('

'. var_export(get_defined_vars(),TRUE) .'

');

in the function to see what you're dealing with.

Actually, all you need to add to the top of your phptemplate_links re-implementation of theme_links is probably:

if (drupal_is_front_page()) {
unset($links['comment_add']);
}

I don't think unset throws any errors or notices if it's deleting something that doesn't work. So this is dirty, but it works. And yeah, that should be easier to theme.

Resolution

Searched words: 
comment links node comment.views.inc edit comment links node metadata drupal theme comment link on teasers drupal disable add new comment links

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.