Hi,

How do I check whether a node has comments enabled or disabled? Right know I have the same "Click to comment" text even if the node doesn't allow comments.

Thanks.

Comments

aklouie’s picture

Admin -> Content -> Content Types -> Edit -> Comment settings

brewthis’s picture

Thank you, however it wasn't quite what I meant.

I need an if-sentence in order to be able to print X if comments are enabled and Y if disabled.

brewthis’s picture

Anyone?

WorldFallz’s picture

In what context are you doing this? Is $node available?

brewthis’s picture

Yep, got $node available - $links and $submitted as well if that matters.

WorldFallz’s picture

Excellent, then you can use:

if ($node->comment == 0) {
  //do something when comments are disabled.
  print "Comments are disabled";
} else {
  //do something when comments are enabled.
  print "Comments are enabled";
}
brewthis’s picture

Lovely, thanks a lot!

Next time, how do I know what's available to me?

WorldFallz’s picture

It rather depends on what context you're in. However, in tpl files you can usually use print_r($vars) or print_r($variables) to get a list of variables. However, that's often a lot of output. If you're in the node.tpl.php and you know $node is available, you can use print_r($node) to see what's available as part of that specific variable.