Categories

WordPress Tricks

I searched all over the Internet to get some advice on this, and all I got were suggestions that didn’t work, and I saw a lot of other people asking the same question, so here you have it:

How to make comments appear on your index (main page) as well as other multi-post pages, such as tag and category pages (specific to WordPress 2.7.1 with K2 RC7 nightly build 2009-02-06)

I hate having to go to a new page just to submit comments, plus it’s weird to not be able to see comments grouped by post on the main page.

  1. In WordPress’ comment-template.php, remove the check that only allows comments on single posts and pages.  Replace this line:
    if ( ! (is_single() || is_page() || $withcomments) )
    with this:
    if ( ! ($withcomments) )
  2. In K2’s header.php, make sure that the comment javascript code is not just placed in single posts and pages.  Replace this line:
    if ( is_singular() ) wp_enqueue_script( ‘comment-reply’ );
    with this:
    if ( comments_open() ) wp_enqueue_script( ‘comment-reply’ );
  3. In K2’s theloop.php, add comments so they’ll appear in multipost pages.  Underneath this line:
    </div><!– .entry-foot –>
    add these lines: 
    <div id=”entry-comments” class=”entry-comments comments”>
    <?php $withcomments = true; comments_template();?>
    </div>
  4. In single.php, you’ll need to remove the reference to comments, otherwise you’ll get double comments thanks to the change you made in theloop.  Remove (or comment out) this entire block:
    <div id=”entry-comments” class=”entry-comments comments”>
    <?php comments_template(); ?>
    </div> <!– .entry-comments –>