My original article dealt purely and simply with creating archives without the use of a plug-in and is an expansion of Zem’s original forum post. It works, it’s flexible and suits many peoples’ purposes however, there are many others who like to have a menu of their archives in their sidebar which can link directly to a particular month contained in the archive. I’m now going to show you how to do just that for monthly archives though it can be adapted to suit category archives as well. This is additional information to my original article so you will need to read that to get to this point.
In order to do what we want we will need some new code and a modification to the original code in my first article. New code first.
You will need to use a “txp:article_custom“ tag in your sidebar or wherever you want the linked list to appear. Here’s the tag:-
<ul class="className">
<txp:article_custom form="archive_sidebar" limit="9999" />
</ul>
The tag is calling for the new form – archive_sidebar – which we are about to create. Call it what you like but remember to change the above tag accordingly. Here’s the code for it:-
<!-- show the year -->
<txp:if_different>
<li class="year"><txp:posted format="%Y" /></li>
</txp:if_different>
<!-- show the month -->
<txp:if_different>
<li class="month"><a href="/sectionName#Y<txp:posted format="%Y%B" />"><txp:posted format="%B" /></a></li>
</txp:if_different>
The first block will drag out the years and the second block drags out the months. You could add a third block for days if you want to take this to the nth degree.
You will see that I have given the “li“ tags for the year and month different class names. This is to allow you to style them differently despite both being contained within the same “ul“ tags (surrounding the “txp:article_custom“ tag). Semantically speaking we should really by using nested “ul“ tags but that is nigh on impossible to reproduce here so I’m not even going to try. Believe me when I tell you that a whole thread was devoted to this subject in the forum without resolution short of changing to a “definition list” or “dl” and I’m not going there either.
Notice that in the above code the months are now linked. You should replace “sectionName” with the name (not the title) of the section you have used for your monthly archives. This is then followed by #Y. The “#” indicates an “anchor link” and the reason for the “Y” is one of validation. You cannot have an id that starts with a number. It’s not allowed so I add in the “Y”. This is then followed by the “anchor” itself which is the “posted” date formatted to show the year and month only. If you wanted to link the “years” as well you could use:-
<li class="year"><a href="/sectionName#Y<txp:posted format="%Y" />"><txp:posted format="%Y" /></a></li>
in the above code.
Again you could include days here so how you format the “anchor links” is up to you but they must match the format used for the “anchors” on the archives page itself, which is where modifying my original code comes in. Here’s that original code which is used for the form that displays the archives page:-
<!-- show the year -->
<txp:if_different>
<a name="Y<txp:posted format="%Y" />" id="Y<txp:posted format="%Y" />"></a><h2 class="className"><txp:posted format="%Y" /></h2>
</txp:if_different>
<!-- show the month -->
<txp:if_different>
<h3 class="className"><txp:posted format="%B" /></h3>
</txp:if_different>
<!-- article title and link -->
<txp:permlink><txp:title /></txp:permlink> (<txp:posted /> optional)
<br />
At the moment this code doesn’t contain any “anchor” tag for the month, and as per Robert’s comment, the anchors for both the “h2” and “h3” can be added to the “h” tags themselves thereby saving us some code so we need to change it like so:-
<!-- show the year -->
<txp:if_different>
<h2 class="className" name="Y<txp:posted format="%Y" />" id="Y<txp:posted format="%Y" />"><txp:posted format="%Y" /></h2>
</txp:if_different>
<!-- show the month -->
<txp:if_different>
<h3 class="className" name="Y<txp:posted format="%Y%B" />" id="Y<txp:posted format="%Y%B" />"><txp:posted format="%B" /></h3>
</txp:if_different>
<!-- article title and link -->
<txp:permlink><txp:title /></txp:permlink> (<txp:posted /> optional)
<br />
See the “name” and “id” attributes within the “h2” and “h3”? They must use the same format as the “anchor link” in your sidebar form. See the “Y”? This is where it is important. It doesn’t matter in your sidebar but it does here, which is why it is needed in the sidebar.
So there you go. You’ve added “anchors” to your archives page and created a tag and form to use in your sidebar. I’ve no doubt that you could modify the menu that appears at the top of the archives page in the same way so that it will link to the months as well as the years and you could modify the whole thing to work for category archives as well, but that’s another article.

