Creating a Site Map Page in WordPress

In this post I will show you how to create an HTML site map in WordPress in about 5 minutes. The site map page will list all your pages and blog posts separated by category. First we will pull all pages using the WordPress function wp_list_pages(). Then we will parse all categories to an array so we can pull all posts corresponding to each category. In the end we will end up having a site map like this one.

1. Create a “Sitemap” Page

Login to wp-admin and create a page named ‘Sitemap’.

2. Add code to create the site map

Locate the file ‘page.php’ in your theme’s folder (/wp-content/themes/your-theme/page.php). Place the following code after the loop:

Alternatively, you may locate ‘page.php’ from wp-admin by going to Appearance > Editor. From the list of files on the right side, select Page Template (page.php)




    'name', 'order' => 'ASC' ); $categories=get_categories($cat_args); foreach($categories as $category) { $args=array( 'showposts' => -1, 'category__in' => array($category->term_id), 'caller_get_posts'=>1 ); $posts=get_posts($args); if ($posts) { echo '
  • name ) . '" ' . '>' . $category->name.'
  • '; echo '
      '; foreach($posts as $post) { setup_postdata($post); ?>
    • '; } } ?>

Voila! now you have a WordPress site map listing all pages and posts separated by category in your site. Enjoy it!

Posted in WordPressTagged

Ready to get started?

Get a Free Estimate