Building an “Archives” Page with Simple PHP - DailyBlogTips |
Building an “Archives” Page with Simple PHP Posted: 17 Jan 2013 07:23 AM PST In my opinion most websites should have an HTML sitemap (also called “Archive” or “Archives”). That is basically a page that will contain a link to all other pages of the site. In case of a blog it will contain a link to all blog posts. Such HTML sitemap is beneficial both for search engines and human visitors. Search engines benefit from it because it becomes easy to crawl all the content of the website. Human visitors, similarly, become able to quickly look for a post that was published on a particular month/day/year. On top of that there’s an SEO benefit, as your link juice will spread evenly across all pages. In order to build such an “Archives” page I used to use and recommend a plugin called SGR Clean Archives. That plugin is quite old, however, and it stopped being updated a while ago. Then a couple of days ago I received an email from a reader who took my recommendation and was using the plugin. He said that his server was becoming really slow lately, and upon further investigation they discovered that the plugin was hammering the server and causing the slowness. He also pointed out that my own “Archives” page was not working anymore. Damn! My guess is that the latest versions of WordPress rendered the plugin’s code slow and ineffective. Anyway I needed to find an alternative. Since performance was a crucial aspect here I decided to implement my own “Archives” page using raw PHP and WordPress functions. It turned out to be an easy task: 1. Create A Template The first step was to create the page template I would use for the “Archives Page”. Basically I copied the structure of a normal page (usually page.php), and added the following piece of code on top:
2. Add the PHP code After that I removed the piece of code that outputs the normal content:
And substituted it with my own PHP code to output the links of all published posts:
3. Create the Page After that all you have to do is to create a page inside WordPress and make it use the “Archives” template. That’s it. I am using that code on my archives page right now. The only thing I am not happy with is the fact that all links are mixed together. I would like to separate them month by month, to make it easier for humans to find what they are looking for. As soon as I solve that problem I’ll post an update, so stay tuned. Original Post: Building an “Archives” Page with Simple PHP |
You are subscribed to email updates from Daily Blog Tips To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
0 comments:
Post a Comment