• Resolved slunk3

    (@slunk3)


    Hello,

    Is there a way to limit the number of posts on the front page by a date range? As in, all posts for the last 30 days.

    Many thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Using the WordPress Default 1.6 theme index.php 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:

    </div>
    
    <?php endwhile; ?>

    to:

    </div>
    <?php } ?>
    
    <?php endwhile; ?>

    Entire index.php posted at https://wordpress.pastebin.ca/746974

    Example to change the number of days from 30 to 45
    $mylimit=45*(60*60*24);

    Thread Starter slunk3

    (@slunk3)

    Great! This works, but is there a way to still access older posts from the index page?

    using

    <?php posts_nav_link(' — ', __('&laquo; Previous Page'), __('Next Page &raquo;')); ?>

    jimmiejo

    (@jimmiejo)

    This works brilliantly.

    I’m using it to display the posts from the past 24 hours.

    If there weren’t any posts in the past 24 hours it obviously displays nothing.

    So my question is, is there a way to use that code and add to it so if no posts are available, it displays the previous day’s?

    Maybe you could add to:

    $mylimit=1*(60*60*24);

    with:

    elseif $mylimit=2*(60*60*24);

    ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Limit front page post by date range’ is closed to new replies.