• I am using the get_posts function in my sidebar while the most recient post is called in the main page by the loop. Though the infromation turned back by the get_posts funciton doesn’t display the correct number of comments for the post it returns. It is displaying the number of comments for the post in the main page. What am I mssing here?

    I currently have the following code in my sidebar:
    <?php $posts = get_posts('numberposts=5&offset=1'); foreach($posts as $post) : ?>
    <div id="<?php the_ID(); ?>">
    <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    <h6><?php if (function_exists('time_since')) { echo time_since(abs(strtotime($post->post_date_gmt . " GMT")), time()) . " Ago"; } else { the_time('F jS, Y'); } ?> | <a href="<?php comments_link(); ?>"><?php comments_number('No Comments','One Comment','% Comments'); ?></a></h6>
    <?php the_excerpt(); ?>
    </div>
    <?php endforeach; ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Add this just after the foreach in your first php tag:

    setup_postdata($post);

    So you have:

    <?php $posts = get_posts('numberposts=5&offset=1'); foreach($posts as $post) : setup_postdata($post); ?>

    Thread Starter jdcfsu

    (@jdcfsu)

    thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_posts comment number?’ is closed to new replies.