Hi,
I am trying to get a block to show only on the comments page for a certain content type. Aside from using arg() to check the URL is there a way to tell that I am on a comments page?
Ideally I would like to be able to do something like:
$node = menu_get_object();
if ($node && $node->type == 'my_content_type' && $node->comments_page) {
// This is a comments page for my content type show the block.
}
Comments
Comment #1
cwgordon7 commentedI'm not sure why you're reluctant to use arg(), it seems ideal in this case. Alternatively, you can use menu_get_item() to check that the menu item is the talk page menu item. If you can explain more about your use case and why you do not want to use arg(), perhaps I'll be able to help you more fully.
Comment #2
justmagicmaria commentedI had the same need -- trying to get a block of content-type specific instructions to show up on the Talk page. ("Please use this page for discussing the Company page and how to improve it, not for comments about the company itself.") Since the path is /node/x/talk, I couldn't specify the block visibility by path and had to use PHP.
There's probably a more elegant way to do that.
This is probably a common need. Perhaps you could add a "Talk page instructions" field to the Comment settings for the content type (under the Talk pages checkbox)?
Comment #3
cwgordon7 commentedSorry, why can't you specify block visibility by path? E.g.:
node/*/talk
That would seem to solve your problem.
Comment #4
cwgordon7 commentedOh, I see, you need to check the node type as well. In that case what you're doing looks fine.
Comment #5
jarodms commented