• Hi,

    I’m on 2.8.5.

    Is there an easy way to restrict my blog to only show posts from the past 3 months, and have an ‘Archive’ link for the remaining?

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Use the Return posts for various date ranges example for your 3 month request. Then might use the template tag, wp_get_archives(), after your loop to provide access to your date archives.

    Related:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    Many thanks for the reply.

    And I would add something like this code to my ‘archive.php’ script?

    <?php
    //based on Austin Matzko's code from wp-hackers email list
      function filter_where($where = '') {
        //posts in the last 30 days
        //$where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
        return $where;
      }
    add_filter('posts_where', 'filter_where');
    query_posts($query_string);
    ?>
    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    Can you confirm if this is correct?
    Should I add the above code to my script.

    I only want to display posts in the past 3 months.

    Thanks

    Actually shouldn’t these these two line be:

    //posts in the last 90 days
        $where .= " AND post_date > '" . date('Y-m-d', strtotime('-90 days')) . "'";

    Yes you can put that in your archives.php (or archive template) just before your loop that might be with something like <?php if (have_posts()) : ?>

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    Thanks for the reply, Michael 🙂

    OK, so I go with:

    <?php
    //based on Austin Matzko's code from wp-hackers email list
      function filter_where($where = '') {
        //posts in the last 90 days
        $where .= " AND post_date > '" . date('Y-m-d', strtotime('-90 days')) . "'";
        return $where;
      }
    add_filter('posts_where', 'filter_where');
    ?>
    <?php if (have_posts()) : ?>

    Would the above do?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Only show posts in the past 3 months…’ is closed to new replies.