WordPress.org

Forums

[resolved] Number of Comments Wrong (3 posts)

  1. twofiverthreetwo
    Member
    Posted 7 years ago #

    Can anybody tell me why this is not showing the correct number of comments? It shows 0 comments for all posts even though there are comments.

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="blog-entry" id="post-<?php the_ID(); ?>">
    <h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title() ?></a></h2>
    <?php the_content('', TRUE, false); ?>
    <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" class="more-link">Continue reading…</a>
    
    <p class='blog-meta' style='float: right; margin-top: -35px; position:relative;'><?php the_time('M j') ?> | <?php comments_popup_link('0','1','%','','none'); ?> Comments
    
    </div>
    <?php endwhile; ?>
    <?php else : ?>
    <div class="blog-entry" id="post-<?php the_ID(); ?>">
    <h2>Missing</h2>
    The page your looking for is not here. It may have never been here or it could have been renamed or moved. You can always try searching again.
    </div>
    <?php endif; ?>
    
    <div class="recent-entries">
    <h2><a href="#">Recent Entries</a></h2>
    <table width="98%" cellpadding="0" cellspacing="0" border="0">
    <?php $myposts = get_posts('numberposts=6');
    foreach($myposts as $post) : ?>
    <tr>
    <td width="425px"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> in <?php the_category(', ') ?></td>
    <td align='left'><?php the_time('M j') ?></td>
    <td align='left'><?php comments_popup_link('0','1','%','','none'); ?></td>
    </tr>
    <?php endforeach; ?>
    </table>
    </div>

    I've tried several comment tags including comments_num and just linking it, etc. They all still show zero.

  2. twofiverthreetwo
    Member
    Posted 7 years ago #

    The comment numbers for the post is showing correctly now however at the bottom for 'recent-entries' it does not show the correct number of comments for each post. Instead it shows the number of comments for all posts to be the same (whatever the number is for the latest post).

  3. twofiverthreetwo
    Member
    Posted 7 years ago #

    I was finally able to get it to do exactly what I wanted. I'll post the code here for anybody else who happens to search for the same problem in the future. The design is for a video blog and only shows the latest post on the main page (as its the video it takes up room). The directly below that shows the past 6 posts including category, date and comment number. This is what I used to finally get it to work exactly how I wanted (note that this is NOT inside The Loop that shows the latest post, I used a second loop for it as my design required it).

    <div class="recent-entries">
    <h2><a href="#">Recent Entries</a></h2>
    <table width="98%" cellpadding="0" cellspacing="0" border="0">
    <?php rewind_posts(); ?>
    <?php // limit the call to 6 posts!
    query_posts('showposts=6&offset=1'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <tr>
    <td width="425px"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> in <?php the_category(', ') ?></td>
    <td align='left'><?php the_time('M j') ?></td>
    <td align='left'><a href="<?php comments_link(); ?>" title="Comment on <?php the_title(); ?>"><?php comments_number('0', '1', '%', 'number'); ?></td>
    </tr>
    <?php endwhile; ?>
    </table>
    </div>

    I don't know if this will be of help to anybody but its here in cast anybody stumbles upon it and can use it.

Topic Closed

This topic has been closed to new replies.

About this Topic