2

I have a news section which is functioning like a blog. Currently in the navigation I am statically listing the years for which content was published. I would like to change this so that ExpressionEngine will automatically generate links to different years only if there are articles that were published that year.

Here is the code I am currently using:

<div class="content-tile">
  <div class="grid_4_desktop grid_4_tablet grid_1_mobile" id="archive-menu">
    <h2 class="title">News</h2>
    <ul>
      <li><a href='{path=news/article/?latest=true}'   <?php if(isset($_GET['latest'])){echo 'class="active"';};?> >Latest Post</a></li>
      <li><a <?php if($year == '2013'){echo 'class="active"';}; ?> href="{path=news/?year=2013}">2013</a></li>
      <li><a <?php if($year == '2012'){echo 'class="active"';}; ?> href="{path=news/?year=2012}">2012</a></li>
      <li><a <?php if($year == '2011'){echo 'class="active"';}; ?> href="{path=news/?year=2011}">2011</a></li>
    </ul>
  </div>

Can anyone tell me how I would change this code so that the years are automatically populated based on when articles were published?

Thanks in advance!

3

Have you taken a look at the Yearlist Add-on?

Then I would think it should be possible to do something like this:

<div class="content-tile">
<div class="grid_4_desktop grid_4_tablet grid_1_mobile" id="archive-menu">
    <h2 class="title">News</h2>
    <ul>
      {exp:yearlist channel="yourchannel" category="1"}
          <li><a href="{path=news/?year={years}}">{years}</a></li>
      {/exp:yearlist}
    </ul>
</div>
3
  • Thanks, that looks exactly like what I need! Unfortunately when I replaced the code with the code above and put my channel name inside channel="" it is not displaying anything in the navigation now. Do I have to do anything other than copy the folder to the third_party folder to activate the plugin? Sorry, still new to EE.
    – APAD1
    Nov 22 '13 at 22:46
  • Nevermind, I was using the name instead of the shortname for channel. Now it's displaying the menu, but instead of showing the year it just shows {year}. Any ideas?
    – APAD1
    Nov 22 '13 at 22:53
  • Took a look at the usage documentation on github.com/ryanirelan/ri.yearlist.ee_addon.2.0 and realized that it's {years} instead of {year}. It's working perfect now. Thanks!
    – APAD1
    Nov 23 '13 at 21:36
2

Get yourself Zoo Triggers and you will love yourself!

{exp:zoo_triggers:archive channel="news" status="open" show_counter="no" type="year"}

Just make sure you give the settings docs a once over to get it set up like you want.

1
  • 1
    Thanks, that looks like an awesome add-on, I will definitely check it out.
    – APAD1
    Nov 23 '13 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.