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' ) );
Was This Tutorial Helpful?