• Hello,

    I am trying to query the posts to establish the four most recent posts and then display them in different places in a template. Anyone have any ideas how to do this? I have tried

    <?php $recentpost = new WP_Query("showposts=1"); while($recentpost->have_posts()) : $recentpost->the_post(); ?>
    								<?php $newest_date = get_the_date( $d ); ?>
    								<?php echo "$newest_date";?>// for troubleshooting
    									<a href="<?php the_permalink(); ?>">featured Image
    									<div class="post-title-bg"><?php the_title(); ?><br/>
    										<?php the_excerpt(); ?>
    									</div></a>
    								<?php endwhile; ?>

    This I believe will give me the newest post. But how can I find the 3 most recent after that and display them not in a list, but in different spots? Any reading or help is appreciated.

    thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Something like this will work, and it won’t reset the standard loop.

    $latest = get_posts( array(
        'numberposts' => 4,
        'orderby' => 'date',
        'order' => 'desc'
    ) );
    
    foreach( $latest as $latest_post ) {
        $newest_date = date( 'd', strtotime ($latest_post->post_date));
        ...
    }

    The only drawback is that you might no tbe able to use some of the standard template functions, as I’ve had to above, but that’s not hard to work around.

    Thread Starter itivae

    (@itivae)

    Thank you for the reply. Ill give that a try.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Check posts dates against other posts to find the 4 most recent’ is closed to new replies.