Today I had a little problem with making HTML site map for 87studios. As you may see I recently switched to Genesis Framework and Metro theme. So now creating custom page templates is not as simple like before in regular theme, but all in all switching to Genesis was a milestone in my blogging life. Little more effort is nothing when you compare Genesis and regular theme performance, power and flexibility.
Why you should have HTML site map?
An HTML site map is a regular web page that can be read by any bot crawling the internet, and by regular web users. HTML site map contains links to pages on your site. If you have a large site, you would list the main pages (e.g. category pages) of the site which takes you to a sub site map with links to pages within that category. It's one of many possible ways to create it. For smaller sites like mine it's enough to make one with ordered links.
In one of Matt Cutts' videos on SEO questions, he answers a question about if you should build an HTML or XML Sitemap.
The solution
After short introduction it's time to create HTML site map. As I mentioned in the first paragraph, there I had some problems at the beginning, but finally I did it using two sources. Yoast's guide and Genesis 404.php file. After juggling with code for a few minutes I got perfect and 100% working template. It's fully compatible with Metro theme, but you should easily adapt it to any Genesis child theme.
So, here is the complete solution to get HTML site map for Genesis Metro child theme.
Just create a sitemap_template.php file, paste my code, save it and upload to your theme folder. As a next step create a blank page, give it a title and change template from default to sitemap. That's all. I hope you enjoy it! Share your thoughts in comments.
<?php
/**
* Genesis Framework.
*
* WARNING: This file is part of the core Genesis Framework. DO NOT edit this file under any circumstances.
* Please do all modifications in the form of a child theme.
*
* @package Genesis\Templates
* @author StudioPress
* @license GPL-2.0+
* @link http://my.studiopress.com/themes/genesis/
*/
/*
Template Name: Sitemap
*/
//* Remove default loop
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'my_sitemap' );
/**
* This function outputs a 404 "Not Found" error message
*
* @since 1.6
*/
function my_sitemap() {
echo genesis_html5() ? '<article>' : '<div>';
printf( '<h1>%s</h1>', __( 'Sitemap', 'genesis' ) );
echo '<div>';
if ( genesis_html5() ) :
echo '<p>' . sprintf( __( 'All pages and post, enjoy :)', 'genesis' ), home_url() ) . '</p>';
else :
?>
<p><?php printf( __( 'All pages and post, enjoy :)', 'genesis' ), home_url() ); ?></p>
<h4><?php _e( 'Pages:', 'genesis' ); ?></h4>
<ul>
<?php wp_list_pages( 'title_li=' ); ?>
</ul>
<h4><?php _e( 'Categories:', 'genesis' ); ?></h4>
<ul>
<?php wp_list_categories( 'sort_column=name&title_li=' ); ?>
</ul>
<h4><?php _e( 'Authors:', 'genesis' ); ?></h4>
<ul>
<?php wp_list_authors( 'exclude_admin=0&optioncount=1' ); ?>
</ul>
<h4><?php _e( 'Monthly:', 'genesis' ); ?></h4>
<ul>
<?php wp_get_archives( 'type=monthly' ); ?>
</ul>
<h4><?php _e( 'Posts:', 'genesis' ); ?></h4>
<ul>
<?php
// Add categories you'd like to exclude in the exclude here
$cats = get_categories('exclude=');
foreach ($cats as $cat) {
echo "<li><h3>".$cat->cat_name."</h3>";
echo "<ul>";
query_posts('posts_per_page=-1&cat='.$cat->cat_ID);
while(have_posts()) {
the_post();
$category = get_the_category();
// Only display a post link once, even if it's in multiple categories
if ($category[0]->cat_ID == $cat->cat_ID) {
echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li><br />';
}
}
echo "</ul>";
echo "</li>";
}
?>
</ul>
<?php
endif;
echo '</div>';
echo genesis_html5() ? '</article>' : '</div>';
}
genesis();
I am using Genesis 'Megazien Pro' child theme and not using Yoast. will it compatable with 'megazine pro' child theme?
if I submit the URL of sitemap page to google search console will it work as sitemap? I will be glad if you answer. Thanks
nice post. i will try it in my client project. thanks a lot.
Hi, looks cool - But you say "copy my code" - can't see it.
Cheers.
My bad, it must be removed with one plugin, fixed now.
Thanks for your attention Tim!
awesome, thanks! Will try it out this weekend.
If you use WordPress SEO by Yoast, just put shortcode on the sitemap page. [wpseo_sitemap]
Wow Aweosme post,Nicely Explained how to create sitemap in Genesis Metro theme,great Work,Thanks.
Thank you! Have you checked tip in comments?
Very nice! I'm just starting out with Genesis myself and also use Yoast's sitemap template, so this was helpful.
However, the way you have it written it doesn't actually output the sitemap content if HTML5 support is enabled. if ( genesis_html5() ) : checks for this, and if it's true then all we get is "All pages and post, enjoy :)" If it's false, we get the same message plus everything else. Nonetheless, a helpful snippet for a newb - thanks for posting!
Hi!
Thanks for response.
If you have errors, try to use shortcut to output sitemap [wpseo_sitemap] you can also choose not to display authors [wpseo_sitemap authors=no] or archives [wpseo_sitemap authors=no archives=no]
Let me know if this helped.