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.

Passing 'year' to channel tag from URL {segment_3}

January 23, 2013 1:49pm

Subscribe [2]
  • #1 / Jan 23, 2013 1:49pm

    lamaison

    15 posts

    Hello, I’m new to EE and building my first set of templates.  I’m trying to pass the ‘year’ in the URL
    ../news/press-releases/2012

    I don’t get any results. But if I hard-code the year in the channel tag, the results display fine.

    {exp:channel:entries channel="press_release"
     dynamic_parameters="year"
     year="{segment_3}" 
     orderby="entry_date" 
     sort="desc"
     disable="member_data|paginate"
    }
    <li>{entry_date format="%m/%d/%y"} - {title}</li>
    {/exp:channel:entries}

    Thanks for your assistance.

  • #2 / Jan 23, 2013 6:18pm

    wildrock

    262 posts

    Hi lamaison,

    The 2012 at the end of your URL would refer to the entry_id. So your channel:entries tag is looking for entry_id=“2012”, which most likely doesn’t exist yet, hence the no result.  EE defaults to the following scheme:

    domain/index.php/template-group/template/entry_id

    Setting the dynamic_parameter also is problematic here, as it is used to grab POST data. So unless you are sending POST data to template, say via a form to choose the year, then it isn’t doing what you expect.

    There’s no reason why you can’t just pass a date variable via the URL like you’re doing, and then pick it up in a parameter. I use search:year=”{segment_3}” style parameters all the time.

    So something like this might work for you:

    {exp:channel:entries channel="press_release"
     search:year="{segment_3}" 
     orderby="entry_date" 
     sort="desc"
     disable="member_data|paginate"
    }
    <li>{entry_date format="%m/%d/%y"} - {title}</li>
    {/exp:channel:entries}

    Best of luck with EE!

    -jim

  • #3 / Jan 23, 2013 8:18pm

    lamaison

    15 posts

    Thanks for your assistance.

    In first test,  I had setup a form that passed the year, and it worked fine.  But then I switched it to URL, and could not get it to work. As I clearly did not have it setup right.

    I changed it to your example and it still did not return any records.

    sample
    domain/I removed index.php/news/press-releases/2012

    {exp:channel:entries channel="press_release"
     status="open" 
     search:year="{segment_3}" 
     orderby="entry_date" 
     sort="desc"
     disable="member_data|paginate"
    }

    while domain/I removed index.php/news/press-releases still returns my 3 demo records

  • #4 / Jan 23, 2013 9:28pm

    wildrock

    262 posts

    Ok, let’s try a little bit different:

    {exp:channel:entries channel="press_release"
     dynamic="no"
     status="open" 
     year="{segment_3}" 
     orderby="entry_date" 
     sort="desc"
     disable="member_data|paginate"
    }

    The dynamic=“no” tag tells the channel:entries tag to not use url segments to fetch data. But the year=”{segment_3}” tag should grab that data and use it. See if that works for you.

    I was assuming that you were using “year” as a custom field, which was how I constructed my publish form (I was building collections of films from certain years). But if you are using the entry_date field to pull your “year” data from, then year=”{segment_3}”  is the correct way to do it.

    -jim

  • #5 / Jan 24, 2013 12:20pm

    lamaison

    15 posts

    Thanks Jim, it works perfect, and yes I am using the entry_date to pull the “year” data. 

    It’s clear I still have a lot to learn on the Channel tag.

    Thanks again.

  • #6 / Jan 24, 2013 3:01pm

    wildrock

    262 posts

    Glad it worked for you! And there’s always something new to learn about EE, everyday.

    -j

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

ExpressionEngine News!

#eecms, #events, #releases