An alternative version for displaying all of your links in an XHTML sitemap now exists.
It’s all very well adding an XML sitemap for the benefit of Google and other supporting search engines, but what about the other visitors to your site, the humans? Step up the XHTML Sitemap.
Creating a sitemap while using the Thesis Theme is a bit different than in other themes, so here’s how I did it.
Instructions
- Create a new page, and save it with the name “sitemap”.
- Make sure the Page Template selection is set to “Custom Template”.
- Open and prepare to edit your custom_functions.php file.
- Add the following:
function xhtml_sitemap() { if (is_page('sitemap') || is_page('707')) { ?> <div id="content"> <div class="post_box top"> <div class="headline_area"> <h1><?php the_title(); ?></h1> </div> <div class="format_text"> <h3>All internal pages:</h3> <ul> <?php wp_list_pages('title_li='); ?> </ul> <h3>All internal blog posts:</h3> <ul> <?php $archive_query = new WP_Query('showposts=1000'); while ($archive_query->have_posts()) : $archive_query->the_post(); ?> <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a> (<?php comments_number('0', '1', '%'); ?>)</li> <?php endwhile; ?> </ul> <h3>Monthly archive pages:</h3> <ul> <?php wp_get_archives('type=monthly'); ?> </ul> <h3>Topical archive pages:</h3> <ul> <?php wp_list_categories('title_li=0'); ?> </ul> </div> </div> </div> <div id="sidebars"> <?php thesis_build_sidebars(); ?> </div> <?php } } add_action('thesis_hook_custom_template', 'xhtml_sitemap');
Tweaks
My sitemap page has the slug “sitemap” and has an ID of 707. Although you might have created your page with the same slug, you should amend the 707 to the ID of your page. You can find this by hovering over the relevant edit link on the Edit Posts page.
Obviously, remember you may also need to add starting and ending PHP delimiters (<?php and ?>) depending on where you put this in your custom_functions.php file.
You may also need to change the div structure to suit how your overall site layout.
If you enjoyed this post, please consider leaving a comment and subscribing to the RSS feed or subscribing via email to have future articles delivered to your feed reader or email inbox.
{ 1 comment }
Hi Gary,
Thanks for sharing your sitemap tip. This worked great for me although I tweaked it a bit so I could use it with the default template vs. the custom template. Here’s a copy of my code:
function xhtml_sitemap() {
if (is_page('sitemap') || is_page('insertyourpageidhere')) { ?>
<h3>Pages:</h3>
<ul>
<?php wp_list_pages('title_li='); ?>
</ul>
<h3>Blog Posts:</h3>
<ul>
<?php $archive_query = new WP_Query('showposts=1000');
while ($archive_query->have_posts()) : $archive_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a> (<?php comments_number('0', '1', '%'); ?>)</li>
<?php endwhile; ?>
</ul>
<h3>Archive Pages by Month:</h3>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>
<h3>Archive Pages by Category:</h3>
<ul>
<?php wp_list_categories('title_li=0'); ?>
</ul>
<?php } }
add_action('thesis_hook_after_post', 'xhtml_sitemap');
Thanks again!
Jeff
Comments on this entry are closed.