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.

Weekly navigation/permalinks

August 13, 2012 7:57pm

Subscribe [1]
  • #1 / Aug 13, 2012 7:57pm

    Nelly

    94 posts

    I’m working on a site that has a news section which displays news (entries) from the last week, using display_by=“week”.
    It should be paginated, to jump to past weeks. However, I need to have the week date or week number in the URL, for example:
    site.com/news/2012/08/08 or site.com/news/2012/32 (using week number). The default EE pagination doesn’t work for this.

    I’ve read this Train-ee post, but I’m still not sure how to make the next/prev pagination, considering there might be weeks without news, so they should be skipped.

  • #2 / Aug 14, 2012 10:39pm

    Nelly

    94 posts

    I’ve had no success with this. At this point, I’d be happy to be able to create weekly permalinks like site.com/news/2012-08-13 or site.com/news/2012-32 (using week number).

    In Mike Boyink’s example, he uses:

    {exp:channel:entries dynamic="no" channel="news" disable="member_data|pagination|categories|custom_fields" orderby="date" sort="asc"}
        {!-- Compare week_date of entry to number appearing in url and show if a match --}
        {if {week_date format="%W"} == segment_3}
            {title} - {entry_date format="%F %d %Y"}
    
        {/if}
    {/exp:channel:entries}

    However, this doesn’t consider the year.

    I tried to do something like this:

    {exp:channel:entries dynamic="no" channel="news" start_on="{segment_3}" display_by=”week” limit="1"}

    But display_by=week and start_on don’t seem to play well together 😕

    I’d appreciate any help!

  • #3 / Aug 15, 2012 10:30pm

    Nelly

    94 posts

    Posting my solution for weekly permalinks, as the solutions I found in the forums had a lot of errors.

    This is for the links:

    {date_heading display="weekly"}
    <a href="/news/week/{entry_date">Week of {week_date format="%d/%m/%Y"}</a>
    {/date_heading}

    The resulting urls look like this: example.com/news/week/2012-08-06

    This is for the permalink page (I’m being lazy and making them in a different template, perhaps later on I will put them in the same template).

    <?php
    // get the entry date from segment_3. If empty, use Monday of the current week.
    $entryDate = $this->EE->uri->segment(3, date('d.m.Y',strtotime('last monday')));
    
    // append minutes and seconds to entry date
    $startDate = date('Y-m-d', strtotime("$entryDate")) . " 00:00";
    
    // add 7 days to entry date, append minutes and seconds
    $endDate = date('Y-m-d', strtotime("+7day", strtotime($entryDate))) . " 23:59";
    ?>
    
    <ul>
    {exp:channel:entries channel="news" dynamic="no" disable="member_data|categories|pagination"
    start_on="<?php echo $startDate; ?>" stop_before="<?php echo $endDate; ?>"}
    {if no_results}There are no results for the chosen week.{/if}
    <li>{title}</li>
    {/exp:channel:entries}
    </ul>

    Allow PHP on template, parsing stage Input.

    Now, if I could only navigate between weeks :(

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

ExpressionEngine News!

#eecms, #events, #releases