Tutorial: Automatic Site Map for WordPress
To improve the navigation of your users as well as search engine traffic and ranking to your WordPress blog I suggest making a good site map of your posts - a map of your site. A kind of user friendly archive of your posts. This is not “Google sitemap”!
The benefits:
- The user can quickly find a specific post he wants anytime he wants.
- The user can quickly see and get an idea how big the blog is get an overview on what the person is writing about.
- All your posts are linked to from a single page to make sure they are not forgotten by the search engines. Basically PageRank is passed to all of them and they are not buried deep down in the archive. If there are no links to your old posts Google will put them in the supplemental index which is not good at all.
There are 3 different versons of site maps that you can use, depending on how you want it. I have used the other 2 until I reached my final which is the first I want to brief you about.
The First WordPress Site Map Example
This one is the nicest, most flexible and best if you write about different subjects but takes some time to set up. Once it is set up it is all automatic. If you have many categories and subcategories this is the best choice for user experience. You can fully decide the headings, order and basically everything. This is the final one for this blog which I currently use and developed myself.
Demo: See my site map here.
Guide how to set it up
- Download and activate the
PHP Exec plugin(for newer versions of WordPress use Exec-PHP) that makes it possible for you to parse PHP in your blog posts. - Download and activate the WP Category Post Plugin that makes it possible for you to list posts per category. (I revised the file a bit, credits to Brian Groce and CrazySerb).
- Create a new WordPress page (not post) with something like this:
<h1 style="margin-top:10px;">Major category</h1>
<div style="margin-left:70px;">
<h2>Subcategory</h2>
<ul>
<?php wp_cat_posts(21); ?>
</ul>
<h2>Subcategory</h2>
<ul>
<?php wp_cat_posts(38); ?>
</ul>
<h2>Subcategory</h2>
<ul>
<?php wp_cat_posts(27); ?>
</ul>
<h2>Other posts on main category</h2>
<ul>
<?php wp_cat_posts(29); ?>
<?php wp_cat_posts(30); ?>
</ul>
</div>
The numbers are the IDs of the categories. Repeat this code until you cover all your categories. You can then place a index with anchor links that jumps to sections like I did. You don’t need to include all posts and you can choose the exact sequence you want. - In your template footer file and or at some other visible place, make a link pointing to your site map for full visitor and search engine link benefit.
The Second WordPress Site Map Example
Use the DDSitemapGen. It is an extensive plugin with a lot of options and is 100% automatic. Just follow the instructions on that site on a new site map page and then in your template footer file and or at some other visible place, make a link pointing to your site map for full visitor and search engine link benefit.
The Third WordPress Site Map Example
This is best if you have a blog in just one subject and is simply just a list of all pages of your blog which can be sorted by date.
Demo:
Here is a demo of just 5 posts:
Guide how to set it up
- Download and activate the
PHP Exec plugin(for newer versions of WordPress use Exec-PHP) that makes it possible for you to parse PHP in your blog posts. - Create a new WordPress page (not post) with some text and then the following lines:
<div style="width:300px;margin-left:50px;font-size:10px">
<br /><br />
<phpcode>
<ol>
<?php wp_get_archives('type=postbypost'); ?>
</ol>
</phpcode>
</div>
There is more about wp_get_archives here.
- In your template footer file and or at some other visible place, make a link pointing to your site map for full visitor and search engine link benefit.
Which kind of site map do you use for your WordPress blog? If you are using the first version it would be nice if you commented with a link to it so we can see how it works for your WordPress blog.

Jim Westergren is a company owner from Sweden who currently lives in Bolivia with his wife. Some of his interests are SEO, web development, writing and
I’ve followed your instructions and keep getting the following error:
Parse error: parse error in \wp-content\plugins\phpexec.php(61) : eval()’d code on line 2
Found the problem - when I copied and pasted this line
the single quotes ended up as not a plain single quote i.e.
‘
but a different style single quote
′
which threw my PHP……
Is there a simple way to add other fields or custom fields to the sitemap listing (e.g. id, region)
Ok thanks a lot for pointing that out. It explains a few things why another also could not get it to work. I have now replaced the ‘ signs with ' and I pasted in notepad and now it is good. I will do the same with my other php lines I have on the blog.
About the wp_get_archives there are more info here: http://wiki.wordpress.org/wp_get_archives and I have now added that to the post as well. Let me know if you have other questions.
I know there is a plugin or something that will replace the 66 / 99 type double-quotes with normal safe ones - and does the same for ordinary single quotes too…
Can’t remember the name of it though.
What I’m trying to do is use the sitemap feature you describe but add another 3 custom fields (very short) to the line(s) that are output. Having a hell of a time….
Have first tried yours, and then the other you suggested and you are using. I like the 2nd better, cause it looks alot better!
Thanks for the information, really helpful!
This article is now majorly revised and republished.
Very useful tutorial.
Thanks. I will try this on my blog.
bye
I’ve been trying to get this to work and I can’t seem to get the post to read the entry. I notice the wp_category plugin suggests PHP4 (untested on php5). Does anyone know if this does work in PHP5? I’m using 5 & wonder if that might be part of my issue.
Actually I don’t know. I use PHP 4 on this site.
very good tutorial.. thanks.. will have to try some of that on my blog..
The plugin DDSitemapGen is indeed nice looking and works well for blogs with a small number of posts.
However when using on sites with 3000+ posts, it’s a dog. Too slow to be of any use.
I took it off after just a few days.
Too bad, because it really is nice looking.
John,
If you set the “Items per page:” to 100 it will break up in different pages and load fast. Or you use any other of my versions, did you try that?
good info — and so simple! I just added the 3rd method to my existing archives for added bang.
Thanks!
Hi there,
I will find it very helpful for my blogs and will pay attention on building it up very soon.
Just wanna say Thanks a lot and keep writing such informations.
Puneet M
Hi All,
That is very good list which help us very well.
I will appreciat that and recommend to others.
And for viewers i Should tell that everybody do post this kind of lists.
With best wishes
Mehul Brahmbhatt
I’m thrilled with this article and will be highlighting it on my blog soon, but I wanted to clear something up that is causing a lot of people great confusion.
In ‘net vernacular, a “site map” is a blog or website’s listing of the articles on the site. A “sitemap” (one word) is a term used by Google and now MSN and Yahoo! to designate a specific type of file created by a sitemap program and stored on a site’s server that helps and guides a search engine through a website.
I HATE it when similar names are used for two different things, but this is how it is today. So you might want to update your article to put spaces between the site and the map so people will understand what you are talking about, which is fabulous information.
And stay tuned for some fun in your traffic.
Oh, and your captcha, like many of these useless things, isn’t working. I tried several times before it went through.
Thanks all.
Lorelle,
Thank you and you are so right! I hate that Google misuse the word sitemap. I have changed my wordings, thanks for clearing that up.
About the captcha, you mean that math question??
The obnoxious math question? Absolutely yes. It’s horrid.
Not only did it take several tries to tell it that 9+4 was 13, it is useless as comment spammers can now break these easily. They are even hiring people to manually break through more complicated captchas. Totally useless. Use Akismet, Bad Behavior, or Spam Karma and give your commenters a break.
The placement of the email notification also stinks, as it automatically subscribes someone, even when they may not want to, as it is below the Submit button. While I’m being critical (hee hee), I recommend you set it to be unchecked by default. You’ll have happier users.
Check out this article for a better perspective.
And stay tuned for fun.
PS: Please delete these notes if you want as they do not add to the conversation on this topic. Just a few kind words of advice and appreciation for the great article you wrote.
I’ve been using the 2nd example for a couple months now and I love it. It took me forever to find a decent plug-in and DDSitemapGen definitely does it’s job well. I think it’s imperative for blogs to have a site map (listed by category preferably). Makes for MUCH easier surfing.
Thanks Lorelle for spreading the link love.
I just see what works for me and use that. Perhaps it does not work the same for you but for me the math question kills 100% of all non-human comment spam. I already have Spam Karma 2 running since the creation of the blog and trackbacks I have disabled totally (not pingback, those are good). When I used the math question when commenting on other blogs it always worked fine.
As for the subscribtions I will have to think about that. It is easy for users to unsubscribe.
Take a look at this:
http://www.blog.mediaprojekte.de/archiv/
I’m going crazy for this sitemap. I don’t understand if it is a plugin: if yes, where I can download this beautiful plugin? If not, you all Gods of WP Plugins that reading this, make it a plugin!
Anyway, thanks for the tips, Jim
Max,
That is not a good example if you think about SEO and search engines. The links in that site map is not in the source code, I think it is called from a javascript.
It is called “King Archives Widget” and is not realesed as a plugin yet.
Wait to say that: I get it. You’re right, it’s called from a javascript, but for SEO and search engines I have the DDSitemapGen already installed in my blog and the sitemap generator for google. The thing here is to provide a more compact way for users to find content when you have a blog with 200 and more posts distributed in over 12 months.
Anyway, King Archives Widget is not the goal here, the goal is Extended live archives, wich is the plugin I’m talking about (now I know). I post the link for people interested in it:
http://www.sonsofskadi.net/extended-live-archive/
Installation is not so easy (or yes? Well, for me not), so I even post the link with instructions:
http://www.24fightingchickens.com/2006/01/03/extended-live-archives/
Plugin support:
http://www.flickr.com/groups/ela-support/
You can have some problem to setting up the plugin and make it work, depend on which version of wordpress you’re running and maybe OS you’re using and maybe browser (anything else?). But on my WP 2.0.4, firefox 2.0 and Win XP, the plugin do his job:
http://www.pulsazioni.net/archivio/
Sorry for little spamming this discussion with all this links (probably I’m a little OT here), but I think people (like me for example) that land on this page searching for a good plugin to organize his blog can be interested in this. Thanks again for your help, Jim
Thanks Max, very appreciated information.
I have followed from Lorelle’s post and have tried to implement method 1 and 2.
Apparently, PHP exec does not work for me (shows nothing, unless I put tags around the code, in which case it shows the code).
I have found Exec-PHP there, which miraculously did the trick.
In the interim, I had used method 2, which I found interesting but less flexible for what I needed to do (in particular, I want to have full control of the order in which categories appear).
Anyway, thanks for the tips.
I think the second example is really the easiest. I just set up a sitemap on another of my blogs and, using that method, had it all done in ~5 minutes.
Previously I had used the first example which took much more tweaking.
Thanks for the writeup.
Thanks for the tutorial Liew. Will be adding the blog Site Map to my blog as well now
Jim… just a quick “hi” and a very big “THANK YOU” for the depth of rich content you post on this site. Honestly, it must be a “labor of love” because I see folks every day of the week charging small fortunes for the info you give out for free!!!
The pay-back of course is that you enjoy far more traffic than many of those other “greed merchants”… and traffic is ALWAYS A GOOD THING:):):)
Regards,
Bruce
Thanks for the tutorial Liew
Thnaks for the download Link. Good work. Till next.
Than you very much.
I looked everywhere for a way to do option #1, I thought I would have to code it myself.
great tutorial. i have 14 blogs — gr8 to implement now
Hello Jim,
You have created a good guideline, thank you!
I did the last option which is 3. For me It the best and many sites use this type of site-map like Tech-Crunch.
Many thank for the great tutorial.
Many thanks for showing us how to do this. It is exactly what I had been looking for to do a Table of Contents for my blog which is at http://www.crankshawontech.com if you want to see how I set it up.
I did have to make one minor change in the wp_category_posts.php file to get a nice looking list format. I changed this line (line 29?):
echo ‘‘ . $post_title . ‘‘;
to this line (replaced the tag with a tag):
echo ‘‘ . $post_title . ‘‘;
Thank you!
Argh! I should have known better than to put code in a comment. I’ll try to re-phrase my previous comment. In the “echo” statement at the end of the wp_category_posts.php file, I deleted the line break tag (BR) and put the entire anchor tag (A) inside a list item (LI) tag.
Hope that makes sense. If it doesn’t and you need the file, send me an email.
David
Another idea to do this without the PHP Exec plugin is to use the #1 or #3 option above, but create a theme file to put the code on.
This is easily done by copying the page.php file from your theme’s directory (or the default theme directory if your theme doesn’t have one), and then modify it slightly to have the desired code from the option chosen. Name the new file with the name of the page (for example, sitemap.php) and you’re done.
According to the template hierarchy, when Wordpress gets a request for a particular page, it looks first for a file by that name, then page.php, then index.php. See http://codex.wordpress.org/Template_Hierarchy
great info, im doing sitemaps this weekend!
Thanks! Going to add this to my website ASAP.
I downloaded this plugin just before I upgraded to Wordpress 2.5.
I was using 2.3 and it worked like a dream (example one).
Then I tried to use it with Wordpress 2.5 and my categories in Wordpress no longer showed category ID numbers.
This is part of the code from example #1:
Major category
Subcategory
Do you have any idea where the category ID numbers can be found in Wordpress 2.5 or how should this code be altered so we get the nice Major Category headers with subcategories below?
Thanks so much for answering.
In WP 2.5 if you mouse over the link for the categories, you will see the ID at the bottom of your browser.
I was looking for something like for a long time… Thanks for the brilliant article. Will try it out on my site.
just heard that there is a plug-in out, that creates sitemap in wordpress… neer used it though. this looks quite interesting and easy.thanks for the info. will surely give it a try this weekend..
Awesome
Thanks Jim on your article, tutorial automatic sitemap in wordpress,
I have always used the google xml sitemap plugin but was never happy with the look of the end result.
This new site map has allowed me to create a very professional looking sitemap, I did have to create a link to my catergories but other than that looks great.
cheers
Used the Second one. Whew! Didn’t know making a sitemap could be this easy.
Thanks for your nice article. Found it as soon as I googled it. Didn’t need to even take a look at the other returns. I got my answer.
One caveat though, my drop-caps plugin acted on it, but not where it is expected to be as you can see in my moralde website. It’s supposed to make large the first character in the page.