0

I am looking for a solution to show the archives for a specific category in my main menu.

The first level menu entry would show the label of the category, say "News Digest", without linking to anything. One level under that, when hovering over "News Digest", I want to show the months of the current year. Below that, I want to show the previous years.

In the end, it would look like:

News Digest

  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • Year 2012
  • Year 2011

Those menu entries would link to pages listing the articles belonging to that category, written during that particular time.

I haven't been able to find any information about how to implement that. I'm a bit surprised as I guess other people probably tried to do that before me.

Is there any plugin that I missed? If not, any indication on how I could implement that myself?

1 Answer 1

0

WordPress has actions and filter to be used to add elements on menu admin, and so it's possible to write a plugin that put on the menu admin screen the month/year archives.

However, that plugin should consist in some dozen lines of code, and once you have not tried to write anyhing, if this was the only way to accomplish your request I think that your question had chances to be cosidere too broad.

But there is a simple way, that require just five minute of manual work and no one line of code.

You can use the 'Links' features of WordPress menu, and manually create the links.

For the top level, once you don't want to link anything, you can use the '#' as url:

top level menu


After that, start creating the month archive links. Note that the links to put here depend on if you have pretty permalink activated or not, and if you have custom rewrite rules or not.

With pretty permalink activated, by defaults month archives are linked with, e.g., example.com/2013/09 so:

month archive


If you have not pretty permalinks activated, the link shuold be something like: example.com?m=201309.

Now repeat same operation for all months, and when you have to add the year archives link, use the url in the form example.com/2013/.

With no pretty permalink the links for year archive is example.com?year=2013.

year archives


This works perfectly, but once links are added manually, has 2 little issues:

  1. Links are not added automatically, when new month arrive you have to manually add the new link. (is possible to write some code that handle auto link creation, but this is another question...)
  2. If you add some custom rules that change the structure of montly and yearly archives url, the link will not works anymore. If you switch off pretty permalinks and you create url using them, urls will not work anymore (but if you switch them on, and link are created using the unpretty url version they continue to works).

Note that shortcode here are taken using WP 3.6.1, menu admin page changed in WP 3.6, so if the yours appear differently is because you have an older version installed.

The workflow described in answer can be done with older version too, but I recommend you, as usual, to keep your WorpPress updated.

2
  • Can I use the same technique for a specific category only?
    – fkoessler
    Commented Sep 24, 2013 at 1:30
  • @Marronsuisse I noticed now that you want to show only one category. If you use the pretty version, append to all url inserted ?category_name=news-digest, so an url will appear something like http://example.com/2013/09/?category_name=news-digest. If you are using the standard urls (no pretty permalink) append category_name after an &, e.g.: http://example.com?m=201309&category_name=news-digest.
    – gmazzap
    Commented Sep 24, 2013 at 2:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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