Creating a site map with WordPress is very simple. You might find it very handy especially if you’re running your whole site on WordPress, because this site map is automatic.
Firstly, you will need to have the Exec-PHP plugin installed. You can download the plugin here.
The plugin allows you to execute PHP coding into posts and pages, and to create your site map you need to use PHP coding. One you have activated the plugin you are ready to go.
Create a new page. It must be a page, not a post. You can choose whatever title you like.
Using the HTML editor, paste the following code:
<ul>
<?php wp_list_pages('title_li='); ?>
</ul>
This will display a site map of all the pages on your website in a bulleted list. By default, all published pages are displayed with no limit to depth and basically, no restrictions. They are also displayed in a hierarchical fashion in alphabetical order by page title.
It’s as simple as that. However, if you’re looking into customising, read ahead.
Customisation
There are many parameters which can be seen at the Codex but I have chosen to only display commonly used ones and how to use them.
sort_column
If you’re not liking the default alphabetical order, you can change your code by adding the parameter in bold:
<ul>
<?php wp_list_pages('title_li=&sort_column='); ?>
</ul>
By using the ampersand (&), you are adding another parameter along with the current one title_li.
sort_column has several variables. You can place these after the equals sign to have them take effect:
post_datesort by creation timepost_modifiedsort by date last modifiedIDsort by numeric post ID (can be seen in the URL when editing a page)post_authorsort by page author’s numeric IDpost_namesort alphabetically by post slug (generally the permalink URL)
For example, this would be your code if you wanted to sort by the post date:
<ul>
<?php wp_list_pages('title_li=&sort_column=post_date'); ?>
</ul>
sort_order
If you aren’t liking the order of the pages and would like to reverse them, use the following code:
<ul>
<?php wp_list_pages('title_li=&sort_order=desc'); ?>
</ul>
Because, by default, the list is ascending. Don’t forget that if you have chosen to change other parameters, you add them along with others using &:
<ul>
<?php wp_list_pages('title_li=&sort_column=post_modified&sort_order=desc'); ?>
</ul>
exclude
Hopefully from reading a bit of the above you’re familiar with how to put the variables together.
exclude allows pages of specified IDs to be excluded from the list. For example, exclude=3,4,56 would exclude pages with the IDs 3, 4, and 56.
include
This is similar to exclude. Simply type in the page IDs of the pages you would like to be included.
For example, include=3,4,56 would include ONLY pages with the IDs 3, 4, and 56.
depth
This parameter controls the levels in the list of pages generated. By default, pages are displayed so that child pages (pages under a parent page) are indented using a nested list. However, this can be changed with the depth parameter and the following variables:
-1– no indents, the pages are listed in “flat” form.1– show only top level pages, and no children pages.2– a value of 2 or greater will specify the depth into which pages are displayed (in terms of parent/child pages).
child_of
This only displays the child pages of a parent page, for instance, the written book reviews listed under a main “book reviews” page. Use as child_of=5, where the number 5 represents the page ID of the parent page.
show_date
This shows the date of the page (next to its name) when it was created or modified. By default no dates are displayed.
modified– shows the date the page was last modified.xxx– anything other than “modified” shows the date of creation of the page.
date_format
By default, if you choose to use show_date above, the date will display the way you have specified in your WordPress options – under Settings, General. This parameter allows you to change it using variables at php.net/date, for example:
<ul>
<?php wp_list_pages('title_li=&show_date=modified&date_format=l, F j, Y'); ?>
</ul>

Subscribe to Heartdrops