Simple Sitemap
On sites where WordPress is being used as a simple Content Management System, it may be appropriate to create a site map page.
One way of achieving this — without resorting to a plugin — is to create a sitemap template within the site’s theme. It is a little trickier than usual because the template has to incorporate a secondary Loop but, once you’ve figured out how to do this, it’s a trick that can come in handy elsewhere.
<?php /*
Template Name: Site Map
*/
?>
<?php get_header(); ?>
<?php get_sidebar(); ?>
<div id="page">
<h2 class="post-title"><?php the_title(); ?></h2>
<?php // MAIN LOOP: display pages
if (have_posts()) : while (have_posts()) : the_post(); ?>
<h3>Pages</h3>
<ul class="sitemap">
<li><a href="<?php bloginfo('url'); ?>">Home</a>
<ul>
<?php
if(get_option('show_on_front') == 'page') $exclude = '&exclude='.get_option('page_on_front');
else $exclude = '';
wp_list_pages('title_li&sort_column=post_title'.$exclude);
?>
</ul></li>
</ul>
<?php endwhile; endif; ?>
<h3>Posts</h3>
<ul class="sitemap">
<?php
// SECOND LOOP: display posts
global $post;
$my_posts = get_posts('numberposts=0&orderby=title&order=ASC&post_type=post&nopaging=false');
foreach($my_posts as $post) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <small>(<?php the_time('j M Y g:i a'); ?>)</small></li>
<?php endforeach; ?>
</ul>
</div>
<?php get_footer(); ?>
Once the template file has been uploaded, create a new page using the Site Map template and publish!
You might also be interested in
FlipFlop 3.0