EE: Yearly Archives plugin

Yearly Archives: een ExpressionEngine plugin. Start Engelse modus…

With this plugin, you can easily set up yearly archives like this (in Dutch, but you’ll get the idea) in an efficient way. You could consider it an alternative to the Archive Month Links Tag. Tested with EE version 1.4.1 build 20060217 and onwards.

Download the Yearly Archives plugin version 1.11

Parameters

  • weblog="blog|news"
  • status="not closed"
  • show_expired="yes"
  • show_future_entries="yes"
  • sort="asc"
  • monthsort="desc"
  • start_month="1" (defaults to the month of the oldest entry)
  • end_month="12" (defaults to the month of the newest entry)
  • start_year="2000" (defaults to the year of the oldest entry)
  • end_year="2010" (defaults to the year of the newest entry)

Tag pairs

  • {months backspace="1"}{/months}

Single tags

  • {year}
  • {year_short}
  • {month_count}
  • {leap_year}
  • {entries_in_year}
  • {month} *
  • {month_num} *
  • {month_short} *
  • {month_num_short} *
  • {num_entries} *

Note: Tags marked with * are available in between the {months} tag pair only.

Example

<ul class="yearly_archives">
{exp:yearly_archives weblog="blog" start_month="1" status="not closed" sort="desc"}
  {if entries_in_year > 0}
  <li>
    {if leap_year == 1}<em>{year}</em>{if:else}{year}{/if}
    <ul>{months}
      <li>
        {if num_entries > 0}
          <a href="{path=blog/archive}{year}/{month_num}/" title="{num_entries} entries in {month} {year}">{month_short}</a>
        {if:else}
          {month_short}
        {/if}
      </li>{/months}
    </ul>
  </li>
  {/if}
{/exp:yearly_archives}
</ul>

New in version 1.1 - 2006.04.28

  • Added parameter monthsort to change the order of months in a year. Defaults to asc

New in version 1.11 - 2007.04.09

  • Fixed a bug where show_expired and show_future_entries were swapped

March 3rd 2006 | Add-Ons, ExpressionEngine | 67 comments


Comments

  1. 1 yoman March 9th 2006, 17:19

    any demo?

  2. 2 Low March 9th 2006, 17:56

    Sure, like I pointed out at the beginning of this post: these archives work with this plugin (and some ajax ^_^). Chris Ruzin uses it too.

  3. 3 maish April 16th 2006, 03:55

    I need a listing of yearly archives for events. The page should list upcoming events from the current year ONWARDS, and on the side, should provide links to past from previous years. How do I do this?

    With EE I had to manually hardcode the current year to get the the page to work.

    Can the plugin avoid the hard-coding?

    See
    http://www.straitsknowledge.com/events/

  4. 4 Low April 18th 2006, 10:35

    Maish, you could probably work around hard-coding the current year by allowing php in your template and adding some code. Take a look at these two threads over at the pMachine forums.

  5. 5 John April 28th 2006, 05:40

    How would you get both the years and months to be descending? Playing around with start_month and sort results in not all entries being displayed. Using your default set-up shows all results but with the months going from Jan - Dec instead of Dec - Jan (ie newest first).

  6. 6 Low April 28th 2006, 10:15

    John, version 1.1 allows for this functionality.

  7. 7 John April 28th 2006, 14:36

    I must’ve just missed this by a few hours did I?

  8. 8 Low April 28th 2006, 16:01

    Actually, I added this to the plugin ’cause it couldn’t do what you asked. I think more people will benifit from this. :)

  9. 9 David October 5th 2006, 17:17

    Hello Low,

    I love your archive plugin. One cient would like to display their archives like this:
    2005
    2004
    2003

    the user clicks a year to display a list of all articles from that year in date order. is this possible with your plugin?

    thanks!

  10. 10 Low October 5th 2006, 18:12

    David, you can create the list of years with this plugin. They could link to another template where you set up a {exp:weblog:entries} tag and have that display entries per year. This plugin doesn’t create lists of entries, just lists of months and years.

  11. 11 Chris January 31st 2007, 12:34

    Sorry for posting in an old topic, but I just wanted to say thank you for this fantastic plugin. You should try to get this into the core of EE 2.0!

  12. 12 joel April 4th 2007, 16:01

    I am not able to show future entries using this plugin - though I am adding in
    show_future_entries=”yes” - is there any further attributes I should be using to make it work correctly?
    Thanks

  13. 13 Low April 4th 2007, 16:25

    Joel, it would appear you’ve discovered a tiny bug! I’ve switched show_future_entries and show_expired around by mistake. I’ll fix this later on. For now, you can use show_expired="yes" to achieve the desired result.

  14. 14 joel April 4th 2007, 21:30

    Excellent! This almost drove me crazy today trying to track down where I had gone wrong, thanks very much for replying so quickly

  15. 15 joel April 4th 2007, 23:02

    Just one thing - how (if possible) can i restrict the listings to the current year only? I am showing an event scheduler and it needs to be restricted to just showing 12 months of entries? Thanks again

  16. 16 Low April 5th 2007, 10:31

    Joel, you should probably enable php in your template for that, explained here, and use $year = $LOC->decode_date("%Y", $LOC->now); to retrieve the current year. You can then use start_year="<?=$year?>" and end_year="<?=$year?>" to show only the current year.

  17. 17 joel April 5th 2007, 22:06

    Ha! Very good - yes of course, that would do the job nicely; thanks again!

  18. 18 Low April 9th 2007, 21:47

    Joel, the bug has been fixed in version 1.11.

  19. 19 Erwin van Lun April 21st 2007, 17:40

    What I would like to to have is just a list like this:
    *2007
    -April
    -March
    -February
    -January
    2006
    2005
    2004
    When someone click on a month, the monthly posting should be shown.
    When someclick of a year, this year should expand (or collaps).

    Is this possible to with your plugin????
    Would be very nice!!!

  20. 20 Low April 21st 2007, 18:26

    Yes Erwin, that’s possible with this plugin. You’ll need to add some JavaScript to toggle the display of the list of months from block to none and vice versa. You can keep the markup almost exactly the same as in the example, only add a link or a span around the year and ids to the nested uls so you’re able to target them with JS.

  21. 21 Erwin van Lun April 21st 2007, 19:13

    Great! Tx for your fast reply.
    Just one question: do you have an example website where I copy the code from (I am not that a Java-guru ;) )

  22. 22 Low April 23rd 2007, 10:12

    Erwin, a Google search for “toggle display javascript” will get you going in the right direction.

  23. 23 Darrin May 4th 2007, 02:21

    Hi Low:

    I ran into a recent problem with this plugin, I posted my question at the EE support forums, would it be best to resubmit here?

    Thank you for producing such a useful plugin!

  24. 24 Martin Hipp June 24th 2007, 10:28

    Feature Request: {switch} tag

  25. 25 Squawk August 26th 2007, 00:42

    Hi Low,
    I really love your ajax archives, however, I do not seem to be able to figure out how to do it. Could you provide some help?
    Is it possible to combine the ajax date archives with a ajax category archive: Depending on what one clicks on the archive list changes. I was planning on doing this own my own site since some time… (If I don’t make sense could you send me an email, maybe we could tackle this together and create a follow-up plugin…)

  26. 26 Low August 26th 2007, 12:22

    Squawk, have you seen my article on Ajax archives? Does that help?

  27. 27 sp1024 September 22nd 2007, 23:18

    My site has multiple sections, I’m having trouble linking to some sort of a page that will display all stories from that month in all of the sections, instead of just one.

    Just the “{month_short}

    How can I specify multiple blogs/sections here?

  28. 28 sp1024 September 22nd 2007, 23:22
  29. 29 Paul November 3rd 2007, 19:32

    Hi, Can this handle category parameter?
    Display a weblog and a specific category only?

    Thanks

  30. 30 Low November 3rd 2007, 21:08

    Paul, there’s no category parameter support at the moment. Sorry…

  31. 31 Paul November 4th 2007, 21:10

    Hi,

    I from this thread on EE where someone managed to implement it but I am not sure where to place the code.
    perhaps you can take a look and enlighted me.

    Cheers, Paul

    Post below:
    ————————————-
    I’ve managed to find a workable solution for me. I’ve changed A few line of code in yearly archive.

    Added:
    $category = $TMPL->fetch_param(’category’) ? $TMPL->fetch_param(’category’) : ”;
    $sql_category = $FNS->sql_andor_string($category, ‘cat_id’);

    and changed SQL query to include:
    INNER JOIN
    exp_category_posts p
    ON
    t.entry_id = p.entry_id

    This adds parameter category to {exp:yearly_archives /}

    ————————————-

  32. 32 Mel November 22nd 2007, 23:50

    Hi, Thanks for the great plugin. One thing I noticed though was that it doesn’t seem to work for entries that are on the 1st of any month. Is there something special I need to do to enable this? Has anyone else had this problem?

    I’m using the following code:

    {exp:yearly_archives weblog=”article” start_month=”1″ status=”not closed” sort=”desc”}
    {months}
    {if num_entries > 0}
    …code here…
    {/if}
    {/months}
    {/exp:yearly_archives}

  33. 33 Steven Hambleton November 25th 2007, 18:26

    It’s a big shame there’s no category support at the moment. I use the Category name in the URL so even the hack above doesn’t help me out.

    It’s a shame as I really just need the {entries_in_year} single tag to for a count comparison in order to close a table of entries where I had a new table for each year.

  34. 34 Low November 26th 2007, 18:48

    @Mel: I haven’t seen that issue before. Can you point me to a working example?

    @Steven: I’ll take category support into account for an upcoming version, if I ever get round to it. And by the looks of it, you shouldn’t be using this plugin for what you need, anyway. Some other custom plugin would be more efficient…

  35. 35 Steven Hambleton November 26th 2007, 23:59

    @Low If only someone would find a solution for me on the forums!

  36. 36 Paul November 27th 2007, 13:42

    Hi Steven,
    Do you know where to place the code I posted above to get it to work?

  37. 37 Low November 27th 2007, 14:31

    Paul, if you must, then here you go:

    Add this code after line #41:
    $category = $TMPL->fetch_param('category') ? $TMPL->fetch_param('category') : '';

    Add this code after line #55:
    $sql_category = $FNS->sql_andor_string($category, 'p.cat_id');

    Add this code after line #68 (before WHERE 1):
    INNER JOIN exp_category_posts p ON t.entry_id = p.entry_id

    Add this code after line #72 (before GROUP BY):
    $sql_category

  38. 38 Paul November 30th 2007, 17:18

    Hi Low, thanks but it doesnt seems to work.

    Do I use it like:

    weblog=”blog” category-id=”2″

    for example

  39. 39 Low December 1st 2007, 12:59

    Paul, try category="2" instead of category-id.

  40. 40 Paul December 1st 2007, 14:44

    Thanks a lot Low! :-)
    Got it working.
    Sorry if I have been a pain on this subject!

    Paul

  41. 41 mike December 20th 2007, 10:43

    This may be two unrelated problems:

    1) My most current month doesn’t appear until I have posted 2 entries
    2) The {num_entries} count for a month is off by one ( shows 0 when there is actually 1 )

    Much thanks

  42. 42 Mike December 20th 2007, 10:59

    Scratch that. Here is description of the real bug:

    I posted an entry at 2007-12-20 03:00 AM - and the plugin didn’t recognize it
    I moved the date back hourly and at 2007-12-19 07:36 PM is when it recognized the entry as being there

    Mysteries!

  43. 43 Low December 20th 2007, 11:23

    @Mike: strange indeed. I’ll look into it as soon as I get the chance.

  44. 44 Vikas January 11th 2008, 14:26

    Hi,

    i m usign this code

    ============

    {exp:yearly_archives weblog=”f1news” start_month=”1″ status=”not closed” sort=”desc” }
    <li>
    {if entries_in_year > 0}
    {if leap_year == 1}{year}{if:else}{year}{/if}
    {months}

    {if num_entries > 0}
    {month_short}
    {if:else}
    {month_short}
    {/if}
    {/months}
    {/if}
    </li>
    {/exp:yearly_archives}
    </ul>
    =============

    What i want is i want to print the months only related to current year & links to rest of the year.

  45. 45 kankuro January 25th 2008, 15:11

    How did you do your archive. I would really like to have something like that on mye site.

    And is it possible to change te location of the news depending on what category the news is. I it is a eview i would like it to go to an other place than the regular news.

  46. 46 Nelly February 15th 2008, 03:58

    Thank you for this plugin, I love it and I have used it in a couple of sites.

  47. 47 Edwin February 25th 2008, 20:41

    Handige tool, als ik het maar werkende kreeg.

  48. 48 Low February 25th 2008, 23:27

    @Edwin: I’d point you in the right direction, if only I’d know what your problem is.

  49. 49 joey April 14th 2008, 18:25

    Hi low, great plugin!

    I’ve been running into a problem with selecting “end_year” however. I’m using some php to get first year and last year as I want to do exactly what #19 does.

    I want current year to default to on and the only way I can think to do this is by having 2 instances of the plugin. The first only showing current year with start_year=”<?php echo $year; ?>” and the second instance end_year=”<?php echo $last_year; ?>”.

    The problem is that the second instance, what is supposed to be last year, is only displaying the number of months of the CURRENT year. So, for example, 2007 months end in April. I thought it might be my php so I hard coded end_year=”2007″ and got the same results.

    Any help is much appreciated :)

  50. 50 joey April 14th 2008, 18:35

    To clarify a little bit:

    Even with only one instance of the plugin, if I say end_year=”2007″ it shows only the number of months for 2008 yet the URL’s display correctly (ie:2007).

    If I say end_year=”2008″ all months and URLs are displayed correctly, but unfortunately this won’t work as we want to be able to target 2008 separately.

  51. 51 Low April 15th 2008, 09:23

    Hi Joey. I’m not entirely sure what you’re trying to accomplish, but if you’re after something like #19, then you’ll need some JavaScript to show/hide the list of months per year. Here’s a snippet of code I used, php on input:

    [PRE]<?php
    $thisyear = date("Y",time());
    $thismonth = date("m",time());
    ?>
    <ul id="yearly_archives">{exp:yearly_archives weblog="blog" start_month="1" start_year="2005" sort="desc"}
    {if entries_in_year > 0}
    <li><a href="#year{year}" class="toggle">{year}</a>
    <ul id="year{year}" class="{if year == "<?=$thisyear?>"}show{if:else}hidden{/if}">
    {months}
    <li>{if num_entries > 0}<a href="{path=blog/archives/}{year}/{month_num}/">{month}</a>{if:else}{month}{/if}</li>
    {/months}
    </ul>
    </li>
    {/if}{/exp:yearly_archives}
    </ul>
    [/PRE]

    Now you can use the classes show and hidden to display or hide the list of months, and you can use the links with class="toggle" to switch between views.

    You can see it something similar right here (bottom left), although that shows 2 years by default if the active month of the current year is April or less.

  52. 52 joey April 15th 2008, 22:34

    Hi again Low!

    Sorry, I should have been more clear. The javascript toggling and all that is functioning. My problem is a basic one and I’ll try and explain it better.

    When I set the plugin to end_year=”2007″, it doesn’t show all the months in 2007. Instead it only shows Jan, Feb, March and April, the same number of months that are in 2008. The URL’s all show the correct year but the number of months is incorrect. end_year=”2007″ should show all months Jan-Dec. However, if I set end year 2008 it shows every year correctly.

    Hope my problem makes more sense now. Again, appreciate your help and love the plugin.

  53. 53 Low April 15th 2008, 23:18

    Hi Joey. I was able to reproduce your problem. I think you can solve it by explicitly defining the end_month parameter: end_month="12".

    Let me know if that works out for you.

  54. 54 joey April 16th 2008, 00:08

    AH! So simple :) Thanks so much, really appreciate it. I hope ya a beer!

  55. 55 joey April 16th 2008, 00:08

    …”owe” that is, not “hope”.

  56. 56 Jeff Adams May 28th 2008, 22:59

    I’m using your plugin to show a list of just the years with entries and I want to display the number of entries next to the year. From what I can tell {num_entries} only works with month listings. Is what I want to do currently possible?

  57. 57 Low June 3rd 2008, 11:59

    Hi Jeff, you could probably use the variable {entries_in_year} for this.

  58. 58 Jeff Adams June 3rd 2008, 18:43

    Ah excellent, that worked perfectly. I didn’t realize that variable existed. I didn’t see it in the usage info.

  59. 59 Joshua Hynes June 4th 2008, 20:19

    One quick question about this plugin:
    Is there any way to show all months in a year even if there aren’t any postings in that month. Just show the month number sans archive link? A good example of this can be found here (see footer for example).

    Thanks.

  60. 60 Low June 4th 2008, 23:43

    Hi Joshua. In fact, the above code example does exactly that. I use almost the same code for my archives, and use css to hide the linkless months. But you can style it any way you want, of course.

  61. 61 Jeff Adams June 5th 2008, 23:12

    I noticed that posts made today (as in the current day) don’t get counted. For example, if I have only one post in June and that post is today June 5 the month link for June doesn’t show up. However if I change the post date to June 4 it does show up. Is this by design or is it a bug?

  62. 62 Low June 9th 2008, 13:21

    Hi Jeff. It might be a bug, but I can’t say for sure, since I can’t duplicate it. Are you still having trouble with this?

  63. 63 matt June 27th 2008, 18:13

    thanks for this - works just as expected. amazing it’s not core to EE!

  64. 64 Timo July 27th 2008, 14:09

    I’m trying to use exp:weblog:entries under each month (a list generated with Yearly Archives) to show links links to each entry posted in that month.

  65. 65 Timo July 27th 2008, 14:15

    I’m trying to use exp:weblog:entries under each month (a list generated with Yearly Archives) to show links to each entry. I’m getting erros with the “month” and “year” parameters in exp:weblog:entries: “Warming: mktime() expects parameter 4 to be long, string given…”

    By manually typing in, for example, 2008 and 07 everything’s ok, but using tags generated by this plugin, {year} and {month_num}, I get that error.

    I’m able to get around this by embedding the exp:weblog:entries part of the code, but I would like to have this working right in the template where I’m using Yearly Archives.

  66. 66 Low July 29th 2008, 20:57

    Timo, I think you’re trying to use the plugin’s output to use as input for the exp:weblog:entries tag, right? But that probably doesn’t work because the latter is parsed before the former. Instead, why not keep the two separate and let EE’s dynamic URLs handle the input for the exp:weblog:entries tag?

  67. 67 Birdie September 30th 2008, 12:52

    THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU

    Sorry about that, but your plugin just saved me a massive headache!

Leave a comment



Some html (a, em, strong, etc) allowed.
Email won’t be displayed and takes care of your Gravatar.