Search code examples
phpwordpresswordpress-theming

Show comments on the category page in wordpress


I am trying to show inline comments after each post on my category page using comments_template() tag.

However, the comments or comment form are not showing up for some reason. The same tag works fine on the content-single page.

By the way I am using WP 3.2.1 along with the twentyeleven theme.


Solution

  • It is possible to do so by forcing the loading of comments. You can force loading of comment by setting the global variable '$withcomments'

    For example, you can put this code in your functions.php

    add_filter('wp_head','sb_force_comment');
    function sb_force_comment( ) {
    global $withcomments;
        if(is_category())
            $withcomments = true; //force to show the comment on category page
      }
    

    It will show the comments as well as the form too on the category page if you are using comments_template() on your category page.

    In case you don't want to show the comment form on the category page, you can do it by putting the following code in your functions.php

    add_filter('comments_open','sb_fake_comments_closed_on_category',20,2);
    
    function sb_fake_comments_closed_on_category ($is_open,$post_id){
      if(is_category())
        return false;
      return $is_open;
    }