Creating Sitemaps In WordPress

We all know sitemaps are important in helping search engines index your website. They’re usually not hard to create either, basically a simple list of links to all of your web pages. Add a new page, add a new link to your sitemap. It can get difficult sometimes if your site grows quickly. It’s easy forget to check on your map and add your latest page. Such is the case with a blog. Well if you use WordPress as your blogging software there’s an easy way to have that sitemap generate itself for you.

As always credit where credit is due. I learned about this technique from Quadzilla at SEO Blackhat through his post Why You Need to Dump that Google Sitemap: Today!. The technique itself is built into the WordPress application through one of the many template_tags you can use. In this case the wp_get_archives tag. There’s also a get_archives tag that offers similar functionality and differs only in the way parameters are passed to the function.

I chose to use wp_get_archives for the new sitemap I’ve added here so I’ll describe things using that tag, but again you can use either. First look for the archives.php file in the folder for the theme you’re currently using. You’ll want to add the following line somewhere inside the file:

< ?php wp_get_archives('type=postbypost'); ?>

By using the type=postbypost parameter the wp_get_archives function will list every post you’ve ever made on your blog starting with the most recent and working backwards down the list until you’ve reached the earliest post.

There are several other type parameters you can use should you like. You can select types to show posts by the month or day and there are additional paramters to limit the number of posts that are displayed should you choose. The one thing I’m not seeing at the moment is a parameter to start the list at a post other than the most recent. It would be nice to have the ability to list the most recent 100 posts on one page and then have a second page listing the next 100 and so on as your blog grows.

You’ll want to customize archives.php to match your theme if you aren’t using a predesigned template or haven’t already modified your archives.php file to match a theme you created. I had to modify mine, but it only took about a minute to include the necessary code.

To create the actual page you’ll want to login into WordPress and naturally enough, write a new page. Just give it a title and make sure to select Archives from the Page Template dropdown. If you have some WordPress pages currently on your blog and don’t want the new sitemap page to appear in the same place those pages are listed you’ll need to exclude it from the template tags that calls those other pages. For me that tag was the wp_list_pages tag and I excluded the post by adding the parameter exclude=pageID. You’ll need to replace pageID with the actual ID used for your sitemap.

You can access the sitemap I created in the link you just read, the sitemap one. There’s also a link in the menu for the blog. I did set the links to change color once you’ve visited them so if you’re wanting to read though all the posts here you can and also keep track of which ones you’ve looked at. Reading all my posts would also make me happy.

The blog is up to 133 posts, which is probably a little long for a sitemap, so I’ll probably spend some time seeing if there’s a better way for me to set things up. I’m sure with a good combination of template tags I can come up with something a little less unwieldy.

Some Changes To This Blog

If you looked at the blog sitemap or caught the title bar you’ll see I’ve renamed this blog TheVanBlog. It’s the first of more changes that will be coming in the next few months, culminating in what should be a complete redesign of the site. You may also notice I’ve removed the monthly archive from the current navigation since I agree with Quadzilla that people really don’t look for what you posted in a specific month or year. If anyone does though, and misses the monthly archive in the navigation let me know and I’ll be happy to put it back. Otherwise don’t expect to see it again.

If you’re observant you’ll also notice another change to the navigation, though I’ll hold off talking about it till sometime next week.

If you have a WordPress blog and a sitemap you’re tired of updating with every new post take a look at the wp_get_archives or the get_archives template tag and create one that updates on it’s own. It’s easy to set up, should reduce the click distance for your posts and help your visitors and search engine spiders find your posts.

Download a free sample from my book, Design Fundamentals.

Leave a Reply

Your email address will not be published.