Forums

get_posts call only returning first post date? (4 posts)

  1. functionista
    Member
    Posted 2 years ago #

    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!

  2. yoshi
    Member
    Posted 2 years ago #

    the_date() is supporsed to displays the date only once for the first post on the same date.

    You can use the_time() instead.

  3. petitpoulain
    Member
    Posted 2 years ago #

    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>
  4. julienmarie
    Member
    Posted 2 years ago #

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

  5. julienmarie
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic