Skip to content

Instantly share code, notes, and snippets.

@sunriseweb
Last active February 26, 2018 17:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sunriseweb/6249242 to your computer and use it in GitHub Desktop.
Save sunriseweb/6249242 to your computer and use it in GitHub Desktop.
Genesis page_archive.php template for creating Site Map that contains all Menus instead of Page (i.e. get all menus using wp_get_nav_menus and steps through to display each using wp_nav_menu).
<?php
/**
* Template Name: Menu-based Site Map
* This file creates a site map based on existing menus instead of using wp_list_pages.
*
* This file is based on the core Genesis file of the same name.
*
* @category Page Template
* @package Templates
* @author Brad Trivers
* @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
* @link http://sunriseweb.ca
*/
/** Remove standard post content output **/
//remove_action( 'genesis_post_content', 'genesis_do_post_content' ); // pre-HTML5
remove_action( 'genesis_entry_content', 'genesis_entry_content' ); // HTML5
//add_action( 'genesis_post_content', 'menu_based_page_archive_content' ); // pre-HTML5
add_action( 'genesis_entry_content', 'menu_based_page_archive_content' ); // HTML5
/**
* This function outputs sitemap-esque columns displaying all menus,
* categories, authors, monthly archives, and recent posts.
*
* @since 1.6
*/
function menu_based_page_archive_content() { ?>
<div class="archive-page">
<h4><?php _e( 'Menus:', 'genesis' ); ?></h4>
<?php
$defaults = array(
'fallback_cb' => 'wp_list_pages("title_li=")',
);
$menus = wp_get_nav_menus();
foreach($menus as $menu) {
$menu_list .= "$menu->slug - $menu->name, ";
$defaults['menu'] = $menu->slug;
$defaults['menu_id'] = 'menu_id_'.$menu->slug;
echo '<h5>'.$menu->name.'</h5>';
echo '<ul>';
wp_nav_menu( $defaults );
echo '</ul>';
}
?>
<h4><?php _e( 'Categories:', 'genesis' ); ?></h4>
<ul>
<?php wp_list_categories( 'sort_column=name&title_li=' ); ?>
</ul>
</div><!-- end .archive-page-->
<div class="archive-page">
<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( 'Recent Posts:', 'genesis' ); ?></h4>
<ul>
<?php wp_get_archives( 'type=postbypost&limit=100' ); ?>
</ul>
</div><!-- end .archive-page-->
<?php
}
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment