• Resolved startribe

    (@startribe)


    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

    So, how do I get comments working? Is it possible?

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter startribe

    (@startribe)

    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

    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

    (@startribe)

    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

    (@startribe)

    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!

    Dear startribe,

    Can you show me how to create a loop within a loop like you have done ?

    thx

    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.