• Resolved aapljack

    (@aapljack)


    I am using get_posts in my footer to get the last five posts. The problem is it is only showing my dates for the first one. Here is the code..

    <?php
    if(is_home()) {
    $archive_posts = get_posts('numberposts=5&offset=1');
    } else {
    $archive_posts = get_posts('numberposts=5');
    }
    foreach($archive_posts as $post) :
    //setup_postdata($post);
    ?>
    <dt><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></dt>
    <dd><? the_date(); ?></dd>
    <?php endforeach; ?>

    Here is the page..

    https://redplaidshirt.com/?p=13

    You will notice that the setup_postdata is commented out. The reason for this is, when I use that, it resets the post number to the last post displayed in the list and directs my comments to post to that last post in the list instead of the current post displayed.

    The footer list works on the homepage because I am using the setup_postdata, since there is no comments to mess up.

    Can anyone tell me why only the first date is displayed?

    Thanks!

    Brian

Viewing 3 replies - 1 through 3 (of 3 total)
  • You really should read the documentation:

    https://codex.www.ads-software.com/Template_Tags/the_date

    Especially the text in the grey box on that page. ??

    HI Brian,

    I use the same code to display the latest posts at the bottom of each of my posts and not the last five. This is why that dispite having an offset=1 after 5 posts you will not see “archives.”

    Instead you’ll have to use a variable to replace offset with that calculates the relevant offset to use for your future posts. This is a problem I am also facing and am looking into it today. Suggestions to fasttrack appreciated.

    As for you date issue… I use <?php the_time(‘F jS, Y’)?> which displays in the format October 3rd, 2005 without a problem. RF

    Thread Starter aapljack

    (@aapljack)

    Thanks! I didn’t realize that about the_date. Works perfect now!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get_posts problem’ is closed to new replies.