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

Comments

  1. author
    1 yoman 9 maart 2006, 17:19

    any demo?

  2. author
    2 Low 9 maart 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. author
    3 maish 16 april 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. author
    4 Low 18 april 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. author
    5 John 28 april 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. author
    6 Low 28 april 2006, 10:15

    John, version 1.1 allows for this functionality.

  7. author
    7 John 28 april 2006, 14:36

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

  8. author
    8 Low 28 april 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. author
    9 David 5 oktober 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. author
    10 Low 5 oktober 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. author
    11 Chris 31 januari 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. author
    12 joel 4 april 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. author
    13 Low 4 april 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. author
    14 joel 4 april 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. author
    15 joel 4 april 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. author
    16 Low 5 april 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. author
    17 joel 5 april 2007, 22:06

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

  18. author
    18 Low 9 april 2007, 21:47

    Joel, the bug has been fixed in version 1.11.

  19. author
    19 Erwin van Lun 21 april 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. author
    20 Low 21 april 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. author
    21 Erwin van Lun 21 april 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. author
    22 Low 23 april 2007, 10:12

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

  23. author
    23 Darrin 4 mei 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. author
    24 Martin Hipp 24 juni 2007, 10:28

    Feature Request: {switch} tag

  25. author
    25 Squawk 26 augustus 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. author
    26 Low 26 augustus 2007, 12:22

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

  27. author
    27 sp1024 22 september 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. author
    28 sp1024 22 september 2007, 23:22
  29. author
    29 Paul 3 november 2007, 19:32

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

    Thanks

  30. author
    30 Low 3 november 2007, 21:08

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

  31. author
    31 Paul 4 november 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. author
    32 Mel 22 november 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. author
    33 Steven Hambleton 25 november 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. author
    34 Low 26 november 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. author
    35 Steven Hambleton 26 november 2007, 23:59

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

  36. author
    36 Paul 27 november 2007, 13:42

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

  37. author
    37 Low 27 november 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. author
    38 Paul 30 november 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. author
    39 Low 1 december 2007, 12:59

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

  40. author
    40 Paul 1 december 2007, 14:44

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

    Paul

  41. author
    41 mike 20 december 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. author
    42 Mike 20 december 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. author
    43 Low 20 december 2007, 11:23

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

  44. author
    44 Vikas 11 januari 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. author
    45 kankuro 25 januari 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. author
    46 Nelly 15 februari 2008, 03:58

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

  47. author
    47 Edwin 25 februari 2008, 20:41

    Handige tool, als ik het maar werkende kreeg.

  48. author
    48 Low 25 februari 2008, 23:27

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

  49. author
    49 joey 14 april 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. author
    50 joey 14 april 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. author
    51 Low 15 april 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:

    <?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>

    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. author
    52 joey 15 april 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. author
    53 Low 15 april 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. author
    54 joey 16 april 2008, 00:08

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

  55. author
    55 joey 16 april 2008, 00:08

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

Leave a comment

Some html (a, em, strong, etc) allowed.


Zoeken in loweblog.com