months ago, Derrick and I opened another blog dedicated to my other
main point of interest: Cinema and Video. After a few weeks of writing content for our blog, quite a bit of information has accumulated. Sometimes, we find it necessary to look at our pasts posts in order to get a piece of information. Browsing back in time has become more and more tedious as we have more content archived. On the very same day, Derrick and I both had the idea that we needed to create an Index page allowing instant access to any posts.
I worked on a template page for WordPress over the weekend in order to display such an index. Our main goal was to simply display a list of posts by date, but as I started to work on this I realized it could be a nice feature to also offer a list grouped by categories and tags. Since the list of posts was bound to grow, I decided to make each section title collapsable while still offering a view all link to display every posts title if so desired.
Before going ahead with the code, I did a quick Google search to see if anyone had worked on this before. What I found was an impressive graphical view of a blog past developped by Vladimir Prevolac based on the default archive page of Tumblr calledSnazzy Archives. I really liked Vladimir’s work and decided to integrate that option as well in my Index page.
As I started working on this, I decided that I would make my work more valuable by making it generic enough to be used by other people. To do so, I knew that I had to make sure of the following:
- Use WordPress core functions
- Not rely on the pre existence of the Snazzy Archives plugin as not everyone would want to use i
- Test my index page with at least three different WordPress installations
It was the first time I tried to extend WordPress, and after a quick Google search I found this function reference page on theWordPress Codex. The documentation, though still being worked on by the community, is easy to read and understand and makes it quite enjoyable to work with the WordPress code. In the end, the only function I had to write was the one returning me the list of months during which at least one blog post had been written. Still, I found the code I needed within WordPress, I just had to adapt it to what I was doing.
Like I said, I really liked Snazzy and wanted to add it to our blog but my Index Template Page couldn’t rely on it to be installed as it might be temporarely disabled or some other user might not want to show it. I simply tested the existance of the plugin before placing the link to the Snazzy Archives in the page.
In order to test, I tried my template on three installations of WordPress. Two running WordPress 2.6 and one running 2.7. I also ran some tests enabling or not the permalinks options as it changes the url handling quite a bit. Regarding this question of URL, I decided not to use Ajax as WordPress front-end doesn’t use it, I decied to make my Index page match the rest of the blog engine on that aspect as well.
All in all, after a few hours of coding and experimenting with WordPress, I had completed my own template page. So far it has worked fine for us, but feel free to report any bug or share your comments with us on this page.
You can download the template here.
- Download the template
- Upload the template archives.php to your theme directory (i.e. <wordpress>/wp-content/themes/<theme_name>
- Make sure your script file can be read
- Adapt the page structure of the template to match your blog theme structure (i.e. copy the beginning and th end of your blog theme index.php page like the content div and sidebar declaration)
- Enter your wordpress administration and write a new page
- Enter the title you wish to see in your menu (be carefull, “index” might generate problems, choose another name)
- Do not enter any content
- Find the page template menu and select “Index Page”
- Publish this new page
- You’re done, go to your blog and test it
If you wish to use Snazzy Archives as well, you also need to:
- Download SnazzyArchives and upload it to your plugin directory
- Go to your administration page and enable the plugin
- Refresh your blog archive page, the link to snazzy archives should appear