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 month and year values from path generated by Archive Month Links tag into channel entries tag to display appropriate month.

December 18, 2011 8:03pm

Subscribe [2]
  • #1 / Dec 18, 2011 8:03pm

    darrenlc

    11 posts

    From the Archive Month Links Tag page in the EE documentation I have set up my links like this:

    <h2><span>News Archives</span></h2>
    <p>   {exp:channel:month_links channel="news-items" limit="50"}<br />
        <a href="http://{path=site/news-archives}">{month}, {year}</a><br />
       <br />
       {/exp:channel:month_links}

    On this same page I have my news items appearing using the following code:

    {exp:channel:entries
         channel="news-items"
         disable="categories|category_fields|trackbacks"
         dynamic="off"
         require_entry="yes"
         limit="19"
         paginate="bottom"
         paginate_base="/news"
         }
                 
          <li><h3><a href="http://{title_permalink=news-item}">{title}</a></h3>
    <p>      <input type="hidden" value="" name="news_id">{entry_date format="%n/%j/%Y"} - </li><br />
         {paginate}<br />
          </ul><br />
          </p>
    
    <p>       {pagination_links}<br />
            {current_page} of {total_pages}<br />
           <br />
         {/paginate}<br />
        {/exp:channel:entries}

    I have not been able to find in the documentation how to take the month and year values from the path generated by the Archive Month Links tag and use them within my news-items entries so that only the entries from the selected month/year appear.

    Could someone point me in the right direction on this?

  • #2 / Dec 18, 2011 8:28pm

    Rob Allen

    3114 posts

    The channel:month tag should insert year and month values into the url automatically, eg so you end up with something like /site/news-archives/2011/12

    You can then query segment 3 and 4 in your channel entries tag like this:

    {exp:channel:entries channel="news-items" year="{segment_3}" month="{segment_4}"}

     

  • #3 / Dec 19, 2011 9:48am

    darrenlc

    11 posts

    Thank you very much!

    Also, is there a way to have only distinct years show up in the Archive Month Links tag? So like a “select distinct” using SQL.

    Right now if I simply delete the month parameter like this…

    {exp:channel:entries
    channel="news-items"
    year="{segment_3}"

    ...then the links are appearing like this:

    2011
    2011
    2011
    2011
    2011
    2010
    2010
    2010 ... etc.

  • #4 / Dec 19, 2011 10:46am

    darrenlc

    11 posts

    Sorry for the unnecessary last question. I overlooked the {year_heading} section in the docs. Here is the code for anyone interested:

    {exp:channel:month_links channel="news-items" limit="50"}
        {year_heading}
        <a href="http://{path=site/news-archives}">{year}</a>
     
        {/year_heading}  
       {/exp:channel:month_links}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases