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.

How do I show only entries posted in the last two weeks?

August 27, 2007 4:06pm

Subscribe [4]
  • #16 / Aug 28, 2007 8:30pm

    allgood2

    427 posts

    Okay from what I gather you want the code should be

    {exp:weblog:entries weblog="mcri" display_by="day" limit="14" orderby="date" sort="desc"}
         <li><a href="http://{path=mcri/index}">{title}</a></li>
     {/exp:weblog:entries}

    I think the problem is, as I mentioned before, the parameters seem to count days with entries, instead of actual days.  You could try the start/end date option mentioned by Sue.

    <?php global $LOC;
              $current_time =$LOC->decode_date('%Y-%m-%d %g:%i %A', $LOC->now - 1209600);
    ?>
    
    {exp:weblog:entries weblog="mcri" orderby="date" sort="desc" orderby="date" sort="desc" start_on="<?php echo $current_time; ?>"}
         <li><a href="http://{path=mcri/index}">{title}</a></li>
     {/exp:weblog:entries}

    Oddly enough, I tested both the stop_before and the start_on and they gave me inconsistent results. There maybe a bug somewhere in here.  Using the start_on, and setting the time two weeks prior. I echoed the ‘current_time’ which is actually two weeks prior (2007-08-14 3:17 PM) I didn’t bother renaming variables. But you can see the start date should be 2007-08-14.. According to the manual

    Only entries that are on or after this date will be included in the display

      But as you can see on my sample page that it clearly extends past the last 14 days, or the date supplied.

    The stop_before zeroed out my results.  The day limit produces the best results, but won’t get you your, show nothing if now events in the last 14 days

    So I’m going to have to recommend using the display by week option, its not an exact count, but since it limits by week, it should include days that have no entries.

    The code for that would be

    {exp:weblog:entries weblog="mcri" display_by="week" limit="2" orderby="date" sort="desc"}
         <li><a href="http://{path=mcri/index}">{title}</a></li>
     {/exp:weblog:entries}
  • #17 / Aug 28, 2007 8:53pm

    aquaadmin

    64 posts

    WOW I think your code did it!

    {exp:weblog:entries weblog="mcri" display_by="week" limit="2" orderby="date" sort="desc"}
         <li><a href="http://{path=mcri/index}">{title}</a></li>
    {/exp:weblog:entries}

    I could have sworn I tried this. Perhaps I left out the orderby parameter as you mentioned earlier. I didn’t try the php option you pointed out, as it seems you came to a conclusion that probably wouldn’t work for me either.

    Interesting the date count this gives me is a bit strange. It wouldn’t stop showing an entry until 8/12/2007 even though it should be 8/14/2007 (two weeks from today). Must be something to do with how it counts weeks. In any case it’s close enough! Thank you, thank you, thank you! That was a toughy (for me at least 😉 ).

  • #18 / Aug 28, 2007 9:20pm

    allgood2

    427 posts

    Yeah, by week, I believe goes by the Sunday through Saturday count. I believe so its not an exact 14 days, but at least it doesn’t only count days with posts.  Glad that worked.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases