• This is what code I’m using in the default theme’s sidebar.php

    <ul>
     <?php
     $myposts = get_posts('numberposts=6&category=1');
     foreach($myposts as $post) :
     ?>
        <li><?php the_date(); ?> <a href="<?php the_permalink(); ?>" title="<?php the_excerpt(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>
     <li>&nbsp;</li>
     </ul>

    and for some reason it only return the first listed post’s date!? Please help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • the_date() is supporsed to displays the date only once for the first post on the same date.

    You can use the_time() instead.

    i had the same problem. But its easy to solve. Just call the function setup_postdata just after you foreach.

    Change to this

    <ul>
     <?php
     $myposts = get_posts('numberposts=6&category=1');
     foreach($myposts as $post) :
    setup_postdata($post);
     ?>
        <li><?php the_date(); ?> <a href="<?php the_permalink(); ?>" title="<?php the_excerpt(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>
     <li>&nbsp;</li>
     </ul>

    I experience exactly the same problem and i do not understand… my setup_postdata was there…but nothing appears

    I experience exactly the same problem and i do not understand… my setup_postdata was there…but nothing appears

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get_posts call only returning first post date?’ is closed to new replies.