I am making a new template and I need to place the comments template outside the wordpress loop and just above the footer in the single.php file.
I searched on google and the best answered I could find related to my issue is in this link:
https://stackoverflow.com/questions/6384205/displaying-the-wordpress-comments-template-outside-the-loop
However, that did not work.
The same comments are appearing on all posts.
So, how can I display the comments display outsite the wp loop?
EDIT: This is the single.php file
<?php
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content-single', get_post_format() ); ?>
<nav class="nav-single">
<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
<span class="nav-previous"><?php previous_post_link( '%link', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'twentytwelve' ) . '</span> %title' ); ?></span>
<span class="nav-next"><?php next_post_link( '%link', '%title <span class="meta-nav">' . _x( '→', 'Next post link', 'twentytwelve' ) . '</span>' ); ?></span>
</nav><!-- .nav-single -->
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<div id="secondary" class="sidebar-area" role="complementary">
<?php get_sidebar(secondary); ?>
<?php get_sidebar(); ?>
</div><!-- #secondary -->
<?php
comments_template( '', true );
?>
<?php get_footer(); ?>
ok, after some research I came up with the solution. The solution is for displaying wordpress comments outside the loop and as a bonus how to place disqus comments outside the loop as well.
First, How to place wordpress comments outside the loop:
In single.php we need to define a new global variable for storing the post id (place this inside the loop)
Then, we can place the list of comments outside the loop with the following code:
You can as well place the comment form and pass the post id as follows:
For DISQUS:
In single.php, We need to define a second variable to get the post title (place this inside the loop):
And then add the following call wherever you want to display your disqus comments:
In your child’s theme functions add the following:
Finally, call disqus_embed outside the loop in single.php
Please feel free to tell me if there is a better way to implement this.