1

Is there a way to show the first page of a node's comments when the node is displayed in teaser format, e.g. on the taxonomy term page? I am building a site with 'posts' (a node type) which have comments, but I want users to be able to read comments, and leave comments from the taxonomy term page.

Is there a way to do this programmatically?

2
  • Not quite sure I get what you're trying to do here. By taxonomy pages do you mean you're looking at a set of your 'posts'?
    – Malks
    Commented Dec 19, 2011 at 1:41
  • @Malks yeah, the taxonomy term page. As in taxonomy/term/* where "*" is the tid. any ideas? thanks! Commented Dec 19, 2011 at 17:17

2 Answers 2

2

Associate a custom node to each taxonomy term.

  1. Create a content type of "taxonomy term page" with comments enabled.
  2. Add a custom field of type "taxonomy term".
  3. Create a View, with a display of type block. Add to it a contextual argument of type taxonomy, and specify from where in the URL path is the argument going to be found. This should filter out nodes based on the current taxonomy found in the URL path. For safety, add a content type filter (regular, non-contextual), and specify "taxonomy term page".
  4. Change the render type from "fields" to "node", or something like that. Try to see if in the node display option, you can choose to render comments as well.
  5. Using Context, add a condition for taxonomy/term/* paths.
  6. In the same Context, add a reaction of type block. Browse and select your block. Add it to the desired region. Save.
  7. ...
  8. Success!

I tried to suggest the "easiest" option, which was using Views. If however for some reason Views won't allow you to render a full node view - with comments enabled - then you will need to create your block programatically using hook node view. But you still get the idea. The purpose is to take advantage of the existing comment-to-node architecture to avoid writing custom code as much as possible.

4
  • yeah, I was actually looking to avoid using views because it's a high traffic site. I was looking for a more programatic way of doing it. Commented Dec 20, 2011 at 5:38
  • If you want a programmatic way then just query the database. Use pager_query() if you want to save yourself some effort. Don't be afraid of using views though.
    – Malks
    Commented Dec 20, 2011 at 14:11
  • @Malks yeah, I just don't see a huge advantage (other than saving some time on development), but the cost is that the performance of the site will not be as good. so I guess it really depends on the overall traffic of the site Commented Dec 21, 2011 at 5:05
  • @Malks see the answer I provided below. Commented Dec 25, 2011 at 1:16
1

I figured it out! with the help of @amateur-barista !

Here's the code I added (replace 'hook' with your module name):

function hook_node_view($node, $view_mode, $langcode) {
  if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
      $node->content['comments'] = comment_node_page_additions($node);
  }
}

thanks!

david barratt

7
  • I am trying to see how this answers the question?
    – Jimajamma
    Commented Dec 25, 2011 at 4:00
  • @JimaJamma, normally a taxonomy term page has the view_mode of 'teaser', I couldn't find a way to easily change the view_mode to 'full'. What I did instead was have Drupal build the comments with comment_node_page_additions and add this to the content array. When Drupal goes to render the taxonomy term page, the node's comments are added to the node's teaser view. (with the code above). So the code above solves my original problem I specified in the question. thanks! david barratt Commented Dec 25, 2011 at 4:44
  • @JimaJamma, to summarize: the answer above is a programatic way to add a node's comments to a taxonomy term page. Commented Dec 25, 2011 at 4:46
  • I guess what I am asking is how does this relate specifically to taxonomy pages? To me, this just seems to create a comments section in a node's teaser view whenever and wherever it's displayed.
    – Jimajamma
    Commented Dec 25, 2011 at 5:34
  • @JimaJamma, where else are teasers used? I guess I could include a check to see what type of page you are on. Commented Dec 25, 2011 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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