Skip to content


Return most recent post by date range

UPDATED: This trick not work with paging. Go to another trick

Want to limit the number of posts on your front page by a date range? For example, display most recent posts for the last 30 days? This works perfectly..

Open index.php template file. Changed this code from:

<?php while (have_posts()) : the_post(); ?>

to:

<?php while (have_posts()) : the_post(); ?>
<?php
$mylimit=30*(60*60*24);
if ( (current_time(timestamp) - get_the_time('U') - (get_settings('gmt_offset') * 3600) ) < $mylimit)
{
?>

and this code from:

 <?php endwhile; ?> 

to:

 <?php } ?>
<?php endwhile; ?>

Posted in How-To, WordPress.

Tagged with , .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.