Archive by year using a single article
Recently I began the conversion to the new theme. It took a day to program the pages, forms and style and another day to add my special tweaks. The rest of the time was devoted to checking articles for proper alignment, site navigation and testing.
One of my special tweaks was an Archives section. When I learned that an article can display other articles, thanks to this TXP Tip, the Archives became easier to deal with. Now all I have to do is create a new article at the beginning of the year, and add the following code to it, change the month=”“ and remember to turn off textile.
Code for the Archive article
<txp:article_custom limit="999" section="articles" month="2009" sort="Posted desc"> <txp:if_first_article><ul></txp:if_first_article> <li> <txp:permlink><txp:title /></txp:permlink>, <txp:posted format="%A %B %d, %Y" />, <txp:rah_function call="rtrim" string='<txp:category1 title="1" link="1" />, <txp:category2 title="1" link="1" />' charlist=", "/> </li> <txp:if_last_article></ul></txp:if_last_article> </txp:article_custom>
Each Archive article’s title is just the year, 2009. The url is
http://bertgarcia.com/2009, short and sweet. One very nice side-effect to this scheme, is that a URL like
http://bertgarcia.com/2006/10/07/google-is-your-friend, which doesn’t exist since I changed the permlink mode, will display the 2006 archive page – no more 404’s.
The only Textpattern plugin I used on this new theme, and probably the only plugin I’ll ever need, is Jukka Svahn’s rah_function plugin. As you can see from the above code block, I use rah_function to strip out the lone comma from the category links, if there’s only one category assigned to the article.
Counting the number of articles
On the Archives section, rah_function came to the rescue again to count the number of live articles on the site:
<txp:rah_function call="safe_count" table="textpattern" where='Section="articles" and Status="4"' />
And also in the footer of an archives article to display the number of articles per year:
<txp:rah_function call="safe_count" table="textpattern" where='Posted rlike "<txp:posted format="%Y" />" and section="articles" and Status="4"' />
While working on this new theme, the Textpattern Tag Reference in downloadable PDF format was a time-saver, thanks Destry.
Soon I plan on releasing this new theme as a download. Creating this new theme made me rethink the Textpattern CMS Themes mechanism, how best to move forward, how can the forms tab be adjusted to accommodate multiple themes, etc.
Thanks to the Textpattern developers, your CMS is a joy to work with.
Editors note: Also see the original TXP Tip on creating an Archive page using an article.