Title: Loop and Commment Solution
Last modified: August 19, 2016

---

# Loop and Commment Solution

 *  Resolved [startribe](https://wordpress.org/support/users/startribe/)
 * (@startribe)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/loop-and-commment-solution/)
 * I’m trying to get my comments for a post to work correctly while operating a 
   loop within a loop.
 * The loop within a loops purpose is to create a main post that has a sub-journal.
   That sub-journal is a list of posts associated with the post. I have the loop
   within the loop working on posts; however, I would like for comments to be available
   on the main post.
 * The primary loop is, I belive, pretty standard code, I will include the html 
   too:
 *     ```
       <?php if (have_posts()) : ?>
       <?php while (have_posts()) : the_post(); ?>
   
       <div class="post" id="post-<?php the_ID(); ?>">
       <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
       <p class="postmetadata"><?php the_time('m.d.y') ?> - <?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
       <div class="post_entry">
       <?php the_content('read more &raquo;'); ?>
       <?php wp_link_pages(); ?>
       </div>
   
       <div id="comments">
       <?php comments_template(); // Get wp-comments.php template ?>
       </div>
       </div>
   
       <?php endwhile; ?>
       <div class="navigation">
       <div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
       <div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
       </div>
       <?php else : ?>
       <h2 class="center">Not Found</h2>
       <p class="center">Sorry, but you are looking for something that isn't here.</p>
       <?php include (TEMPLATEPATH . "/searchform.php"); ?>
       <?php endif; ?>
       ```
   
 * And this is the code I post within a post through WordPress (Exec-PHP plugin 
   activated):
 *     ```
       <?php $my_query = new WP_Query('tag=Eng-4+Notes');
       while ($my_query->have_posts()) : $my_query->the_post();
       $do_not_duplicate = $post->ID; ?>
       <?php the_title(); ?>: <?php the_time('m.d.y') ?>
       <?php the_excerpt_reloaded(200, '<img><p>', '', TRUE, '', FALSE, 1); ?>
       <?php endwhile; ?>
       ```
   
 * Now again, the main post and sub-posts generate, but the current comments for
   the main posts does not appear. Here is a link to the page (one single entry 
   under Class Journal, I may be editing it too:
    [http://joelsimone.com/content/?p=43](http://joelsimone.com/content/?p=43)
 * So, how do I get comments working? Is it possible?
 * Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Thread Starter [startribe](https://wordpress.org/support/users/startribe/)
 * (@startribe)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/loop-and-commment-solution/#post-691087)
 * Ok, I figured out the comment displayed on the main page is the one associated
   with the last comment:
    [http://joelsimone.com/content/?p=43#comment-9](http://joelsimone.com/content/?p=43#comment-9)
 * So it looks like I need to reset the loop in some way, or to get the loop to 
   re-recognize the main loop query again. I was assuming this would be put before
   the comment section.
 * I’m doing my best, but I’m still new to php and programming, so any help is greatly
   appreciated.
 *  Thread Starter [startribe](https://wordpress.org/support/users/startribe/)
 * (@startribe)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/loop-and-commment-solution/#post-691092)
 * **RESOLVED!**
 * I stopped trying to run into the brick wall, found the doorway, and it was through
   ending the first loop from the main post before beginning a new independent and
   refreshed comment loop. It worked!
 * Here is my final code:
 *     ```
       <?php if (have_posts()) : ?>
       <?php while (have_posts()) : the_post(); ?>
   
       <div class="post" id="post-<?php the_ID(); ?>">
       <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
       <p class="postmetadata"><?php the_time('m.d.y') ?> - <?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
       <div class="post_entry">
       <?php the_content('read more &raquo;'); ?>
       <?php wp_link_pages(); ?>
       </div>
       <?php endwhile; ?>
       <?php endif; ?>
   
       <?php rewind_posts(); ?>
       <?php if (have_posts()) : ?>
       <?php while (have_posts()) : the_post(); ?>
       <div id="comments">
       <?php comments_template(); // Get wp-comments.php template ?>
       </div>
       <?php endwhile; ?>
       <div class="navigation">
       <div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
       <div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
       </div>
       <?php else : ?>
       <h2 class="center">Not Found</h2>
       <p class="center">Sorry, but you are looking for something that isn't here.</p>
       <?php include (TEMPLATEPATH . "/searchform.php"); ?>
       <?php endif; ?>
       </div>
       ```
   
 *  Thread Starter [startribe](https://wordpress.org/support/users/startribe/)
 * (@startribe)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/loop-and-commment-solution/#post-691093)
 * I’m sure some code maybe redundant… and there is a better way, because I’m so
   new at this. So any additional suggestions to clean it up are welcome; otherwise
   this is resolved.
 * Thanks!
 *  [decees](https://wordpress.org/support/users/decees/)
 * (@decees)
 * [18 years ago](https://wordpress.org/support/topic/loop-and-commment-solution/#post-691378)
 * Dear startribe,
 * Can you show me how to create a loop within a loop like you have done ?
 * thx
 *  [decees](https://wordpress.org/support/users/decees/)
 * (@decees)
 * [18 years ago](https://wordpress.org/support/topic/loop-and-commment-solution/#post-691379)
 * Sorry, I haven’t read the code correctly :”>
    I got it .

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Loop and Commment Solution’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 5 replies
 * 2 participants
 * Last reply from: [decees](https://wordpress.org/support/users/decees/)
 * Last activity: [18 years ago](https://wordpress.org/support/topic/loop-and-commment-solution/#post-691379)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
