ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Limiting date range of posts

June 25, 2007 4:42pm

Subscribe [1]
  • #1 / Jun 25, 2007 4:42pm

    sherrills

    26 posts

    I’ve been banging my head to try and get this to work.

    I basically want to display all posts entered 3 days ago, or 4 days ago.  This needs to be dynamic so that it’s always 3 or 4 days ago from the current date.

    Could someone show me what this code would look like?

  • #2 / Jun 25, 2007 6:31pm

    Oxygen Smith

    120 posts

    Have you started with the PHP code on the User Guide page that shows how to generate a dynamic date for the “start_on” parameter?

  • #3 / Jun 25, 2007 6:39pm

    sherrills

    26 posts

    Yes, i’ve looked at all of that - i still can’t seem to put it all together though.  I was hoping someone could post something that I could copy and paste that literally shows how to display all posts that occured 3 days ago.  I could tweak it from there to get it to do what I needed.

  • #4 / Jun 25, 2007 11:36pm

    Oxygen Smith

    120 posts

    Have you tried doing a whole bunch of code and it’s not working, or you’re just stumped on how you’d begin? I’m not a PHP wizard by a long shot (so I have no template to give you, sorry.) But wouldn’t it just involve using some PHP date math:

    <?php
    $three_days_ago  = mktime(0, 0, 0, date("m")  , date("d")-3, date("Y"));
    ?>

    ... and then setting ‘start_on’ to $three_days_ago? Actually you’d have to generate two PHP variables: the start date/time and the end date/time, to drop into ‘start_on’ and ‘stop_before.’

    (Above code is from http://ca.php.net/date by the way)

    Maybe post what you’ve got here and let us take a look at it?

  • #5 / Jun 26, 2007 1:48am

    sherrills

    26 posts

    Here’s what I’ve been using.  The cutoff works just fine.. I just want to find a way to set the start_on. 

    {exp:weblog:entries orderby="date" sort="desc" limit="16" weblog="foo" 
              
    <?php 
    $cutoff_date = 
    date("Y-m-d H:i", mktime(date("H"), date("i"), 0, date("m"), date("d")-3, date("Y")) ); 
    
    echo ' start_on="' , $cutoff_date, '" '; ?> 
    }
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases