Skip to content

Instantly share code, notes, and snippets.

@ChrisCree
Created October 21, 2015 18:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisCree/d3ff68e00c52bea6e783 to your computer and use it in GitHub Desktop.
Save ChrisCree/d3ff68e00c52bea6e783 to your computer and use it in GitHub Desktop.
Genesis 2.2+ custom archive page template for customizing sitemap output. Copy the page_archive.php file, edit it as desired per the Usage.txt instructions below, and FTP it up to your Genesis child theme directory. Then create a page using the Archive page template to display your results.
<?php
/*
*
* Template Name: Archive
*
* Replaces standard Genesis Archive page template to allow for customization of output
*
*/
//Replace the content
remove_action( 'genesis_post_content', 'genesis_do_post_content' );
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
add_action( 'genesis_post_content', 'wsm_page_archive_content' );
add_action( 'genesis_entry_content', 'wsm_page_archive_content' );
function wsm_page_archive_content() {
$heading = ( genesis_a11y( 'headings' ) ? 'h2' : 'h4' );
wsm_sitemap( $heading );
}
function wsm_sitemap( $heading = 'h2' ) {
// edit these functions as desired with the parameters listed in the WordPress Codex
$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' ) );
echo $sitemap;
}
genesis();
The functions can be modified as needed using parameters from the WordPress Codex.
For example, to exclude specific pages line 30 above would be changed to this instead:
$sitemap .= sprintf( '<ul>%s</ul>', wp_list_pages( 'title_li=&echo=0&exclude=174,180' ) );
Where 174 & 180 are the page ID's of the pages to be omitted.
Here are the respective Codex pages for each function to find what parameters can be used:
wp_list_pages()
https://codex.wordpress.org/Function_Reference/wp_list_pages
wp_list_categories()
https://codex.wordpress.org/Function_Reference/wp_list_categories
wp_list_authors()
https://codex.wordpress.org/Function_Reference/wp_list_authors
wp_get_archives()
https://codex.wordpress.org/Function_Reference/wp_get_archives
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment