Can I seperate comments from post?

Most starter themes now, like Twenty Eleven, come with separate files for each template — for example, single.php and content-single.php represent the Single (Post) template in Twenty Eleven.

The starter theme I use, Reddle (ddl), has the same template hierarchy, and here’s the solution I am using…

  1. Create a blank Page (NOT Post) titled “Comments, Questions and Feedback” or something of your choice. Leave the body blank, and publish the page.

  2. Make a copy of single.php and rename it to page-comments.php (where “comments” in page-comments.php is the slug of the Page we created above).

    (A) In it, replace this:

    <?php while ( have_posts() ) : the_post(); ?>
    

    with this:

    <?php
        $p = $_GET['u'];
        $the_query = new WP_Query("showposts=1&p=" . $p);
        while ( $the_query->have_posts() ) : $the_query->the_post();
    ?>
    

    (B) Also replace this:

    <?php get_template_part( 'content', 'single' ); ?>
    

    with this:

    <?php get_template_part( 'content', 'comments' ); ?>
    
  3. Make a copy of content-single.php and rename it to content-comments.php (in content-comments.php “comments” should be the same as the parameter you use in <?php get_template_part( 'content', 'comments' ); ?> as shown above 2(B)).

    Now depending on what content you want to show on the standalone Comments page, edit out all the code in the template. For example, the first thing you might want to remove is the code that outputs the post’s content.

    For example, this is the original content-single.php of my theme, and after editing out all the unnecessary code (that I didn’t want to show on the Comments page), this is what is left in the file:

    <?php
    /**
     * The default template for displaying post comments.
     *
     * @package Reddle
     * @since Reddle 1.0
     */
    ?>
    
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <header class="entry-header">
            <h1 class="entry-title"><a href="https://wordpress.stackexchange.com/questions/52275/<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'reddle' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
    
            <?php if ( comments_open() || ( '0' != get_comments_number() && ! comments_open() ) ) : ?>
            <p class="comments-link"><?php comments_popup_link( '<span class="no-reply">' . __( '0', 'reddle' ) . '</span>', __( '1', 'reddle' ), __( '%', 'reddle' ) ); ?></p>
            <?php endif; ?>
        </header><!-- .entry-header -->
    </article><!-- #post-<?php the_ID(); ?> -->
    
  4. Add a rewrite rule to your .htaccess file to make the URL to the Comments page pretty:

    RewriteRule ^comments/([0-9]+)/?$ /comments/?u=$1 [QSA,L]
    

    Now, the Comments page for a post would be http://example.com/comments/17/ if 17 is its post ID.

  5. How will your readers know where to leave comments unless you link to the comments page? So, in your content-single.php or any template appropriate to you (depending on where you want to show the link), use this code:

    <a href="https://wordpress.stackexchange.com/comments/<?php the_ID(); ?>/">Leave A Comment!</a>
    

It’s really simple, and there’s no additional CSS involved as your comments pages inherit the same template as your posts. Yes, I did try this before sharing the answer here. It worked like a charm!

SCREENSHOTS

(Rough but working…)

Screenshot


Based on “Provide a Better Reading Experience in your WordPress Blog” by Amit Agarwal.

Leave a Comment