This code uses wp_get_archives with the post_type=portfolio
parameter to add custom post type pages to the site map included in Genesis.
Here’s the code you can add to your child themes functions file.
add_filter( 'genesis_sitemap_output', 'modify_sitemap' );
function modify_sitemap() {
$heading = ( genesis_a11y( 'headings' ) ? 'h2' : 'h4' );
$sitemap = sprintf( '<%2$s>%1$s</%2$s>', __( 'Pages:', 'genesis' ), $heading );
$sitemap .= sprintf( '<ul>%s</ul>', wp_list_pages( 'title_li=&echo=0' ) );
$sitemap .= sprintf( '<%2$s>%1$s</%2$s>', __( 'Categories:', 'genesis' ) , $heading );
$sitemap .= sprintf( '<ul>%s</ul>', wp_list_categories( 'sort_column=name&title_li=&echo=0' ) );
$sitemap .= sprintf( '<%2$s>%1$s</%2$s>', __( 'Authors:', 'genesis' ) , $heading );
$sitemap .= sprintf( '<ul>%s</ul>', wp_list_authors( 'exclude_admin=0&optioncount=1&echo=0' ) );
$sitemap .= sprintf( '<%2$s>%1$s</%2$s>', __( 'Monthly:', 'genesis' ) , $heading );
$sitemap .= sprintf( '<ul>%s</ul>', wp_get_archives( 'type=monthly&echo=0' ) );
$sitemap .= sprintf( '<%2$s>%1$s</%2$s>', __( 'Recent Posts:', 'genesis' ) , $heading );
$sitemap .= sprintf( '<ul>%s</ul>', wp_get_archives( 'type=postbypost&limit=100&echo=0' ) );
$sitemap .= sprintf( '<%2$s>%1$s</%2$s>', __( 'CPT Portfolio Items:', 'genesis' ) , $heading );
$sitemap .= sprintf( '<ul>%s</ul>', wp_get_archives( 'type=postbypost&limit=10&echo=0&post_type=portfolio' ) );
return $sitemap;
}
Swap out portfolio in the above code with the name of your CPT.
You could also use wp_list_pages like this:
$sitemap .= sprintf( '<%2$s>%1$s</%2$s>', __( 'Portfolio Items:', 'genesis' ) , $heading );
$sitemap .= sprintf( '<ul>%s</ul>', wp_list_pages( 'title_li=&echo=0&post_type=portfolio' ) );
Hi! Thank you for this! What if I just wanted the CPT titles to list/link on the sitemap, versus a list of posts below the CPT title? Any ideas on how I can do this? I have way too many posts/categories under the CPT’s to have them listed, but would be great to have an easy link for folks to go to that CPT. I hope this makes sense :).
Micki, You can do that by modifying the PHP code which is something i support for members.