Drupals standard practice of printing node comments below the node can get a bit stale. Sometimes you may want, or simply need to, print them somewhere else. Wouldn’t be great if comments and the comment form were just variables you could move around?
Well you can—thanks to Drupal 6’s phptemplate_preprocess_page function we can easily store both the comments and the comment form in variables. The only caveat is that you must set the comment reply form to a separate page first, or something might break.
The following snippets store the comment form and comments in variables and allow you print them in page.tpl.php.
// Store comments and the comment form in variables
function phptemplate_preprocess_page(&$vars) {
$vars['comments'] = $vars['comment_form'] = '';
if (module_exists('comment') && isset($vars['node'])) {
$vars['comments'] = comment_render($vars['node']);
$vars['comment_form'] = drupal_get_form('comment_form',
array('nid' => $vars['node']->nid));
}
}
// Unset comments from node
function phptemplate_preprocess_node(&$vars) {
$vars['node']->comment = 0;
}
?>
Now you can print $comments and $comment_form anywhere in page.tpl.php, and they will only print when you are viewing a node.
Well you can—thanks to Drupal 6’s phptemplate_preprocess_page function we can easily store both the comments and the comment form in variables. The only caveat is that you must set the comment reply form to a separate page first, or something might break.
The following snippets store the comment form and comments in variables and allow you print them in page.tpl.php.
// Store comments and the comment form in variables
function phptemplate_preprocess_page(&$vars) {
$vars['comments'] = $vars['comment_form'] = '';
if (module_exists('comment') && isset($vars['node'])) {
$vars['comments'] = comment_render($vars['node']);
$vars['comment_form'] = drupal_get_form('comment_form',
array('nid' => $vars['node']->nid));
}
}
// Unset comments from node
function phptemplate_preprocess_node(&$vars) {
$vars['node']->comment = 0;
}
?>
Now you can print $comments and $comment_form anywhere in page.tpl.php, and they will only print when you are viewing a node.
Hello thank you about this preprocess function but when i have pasted in template.php file i have received error could you help me?
ReplyDeletehttp://www.gurutechnoworld.com/on_page_optimization_services.php
ReplyDeleteWe offer on page optimization services. We have young and dynamic SEO team. All team members are perfect in on page optimization. Our all SEO work is according to Google algorithms
It would be nice to see how you do the same in Drupal7.
ReplyDeletethis is very useful for me since I'm a new user of drupal, thanks!
ReplyDeleteVERY informative. I'll be making some juice in the near future. Passing this onto my friends. Thanks.
ReplyDeleteI recently came across your blog and have been reading along.
ReplyDeleteI think I will leave my first comment. I don’t know what to say except that I have enjoyed reading.
Nice blog. I will keep visiting this blog very often.
Do you need on page optimization service??
ReplyDeleteplease read our short description below and follow our page url: http://eseobook.com/web-page-optimisation-services.html
Why We are the best:
We have smart seo member to do all kind of on page optimization. Our professional team can ready a top quality seo optimized page from the root keyword selection to the latent semantic content writing.
Informative article, I really like to keep track of the updates and news. Thanks for the excellent news and topics.
DeleteI'm impressed. You're truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. I'm saving this for future use.Led Outfitters
ReplyDeleteLed Outfitters
Led outfitters reviews
led outfitters reviews
led outfitters complaints
led outfitters complaints
led outfitters reviews complaints
This comment has been removed by the author.
ReplyDeleteDrupal is amzing sir , visit my blog Puppy information
ReplyDeletethanks to Drupal 6’s phptemplate_preprocess_page operate we will simply store each the comments and also the comment type in variables. the sole caveat is that you just should set the comment reply type to a separate page initial, or one thing may break.
ReplyDeleteThe tutorial on Drupal to print comment anywhere in drupal is not having comprehensive information. Please post regularly with latest in this.
ReplyDeleteThis is really very informative blog and it helps me a lot. Thanks for making such a informative blog for us. Keep blogging.
ReplyDeleteweb development melbourne | website development company melbourne
Been looking for such an amazing web journal like this for quite a while.
ReplyDeletewww.canvasprints.com
thanks this is good blog. antminer s17 pro setup
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteIt is now very easyfor you to look for a Print Shop Singapore that is justnear your area because now you can use the Internet for that. No need
ReplyDeletefor you to explore because in just a few seconds, you will beable to find what you are looking for.
If you are looking for a great quality working Print Shop in Singapore, then you don’t have to look any furtherbecause there is a legit and high quality printing company for your every need.
ReplyDeleteThis particular is usually apparently essential and moreover outstanding truth along with for sure fair-minded and moreover admittedly useful My business is looking to find in advance designed for this specific useful stuffs… Print Shop
ReplyDeleteIf you want a high and excellent quality ofphotos for your advertisement needs or simply for Print Shop
ReplyDeleteThe post is written in very a good manner and it contains many useful information for me. scootersleuth.com/reviews/best-self-balancing-scooters-hoverboards-kids/
ReplyDeleteSpot lets start on this write-up, I truly think this fabulous website requirements considerably more consideration. I’ll visit here
ReplyDeleteI’d constantly want to be update on new content on this website, bookmarked! flatbed print
ReplyDelete