This is a really neat idea but I'd like to expand upon it. In his post, David Kennedy writes out some code to allow a basic wp_list_pages
type feature for Custom Post Types to use as a sitemap. His code is as follows:
<h2 id="posts">My Post Type</h2>
<ul>
<?php
$terms = get_terms( 'my_taxonomy', 'orderby=name' );
foreach ($terms as $term) {
echo "<li><h3>".$term->name."</h3>";
echo "<ul>";
$args = array(
'post_type' => 'my_posttype',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'my_taxonomy',
'field' => 'slug',
'terms' => $term->slug
)
)
);
$new = new WP_Query($args);
while ($new->have_posts()) {
$new->the_post();
echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
}
echo "</ul>";
echo "</li>";
} ?>
</ul>
I like this idea but am wanting to take it a bit further. It'd be great to add depth, or levels of hierarchy, and to show parent/child relationship results instead of listing Custom Post Types alphabetically. In other words, mimic more of the functions that wp_list_pages
offers.
Is there an easier way to do this or is there functionality in WordPress that already does what I'm looking for?