Why would you need to put Drupal comments into a block? Well, recently I was working with another developer that decided to use Quick Tabs to create a menu that would show the current content type’s comments. Quick Tabs uses blocks, so there is one reason I can think of.
Ok, so getting the content type’s comments into a block is pretty easy once you know how.
This method will require you to use PHP code from within the block you will create to show the comments. So the first thing is to make sure that this is possible by going to site building and then modules and turning on the PHP Filter under the category of Core Optional (if it is not already on that is).
NOTE: Check at
admin/settings/filters to be sure that only trusted roles can use the PHP filter, otherwise your web site could be vulnerable to attack. By default, only the administrator can use this filter.
Create a new block and select a region for it. Put the following code on the body textarea:
Do not forget to select the PHP filter from the list of the input filters. After entering the rest of the settings for your block click save.
Now your new block should be ready to assign to whatever region you want. If the page you load has comments related to it. They should now appear via the block.
The arg() funtion may seem a bit cryptic if you’re new to Drupal. Here is a quick explanation from George Notaras in his post: Drupal Tip: List a node’s taxonomy terms inside a Block which I found helpful in compiling this information.
“Now to some technical details about arg(0) and arg(1), which probably seem a bit cryptic to a user that is not experienced with Drupal (like me). Assume we have the following URL to a node:
www.example.org/node/23, which means that the path to the page is
/node/23. Well, arg(0) is the
nodepart and arg(1) is the second part;
23that is. Read about the arg() function.”
I hope this was helpful.