Skip to content

Instantly share code, notes, and snippets.

@carasmo
Last active February 28, 2016 15:43
Show Gist options
  • Save carasmo/999c2f5d7b6044846d4d to your computer and use it in GitHub Desktop.
Save carasmo/999c2f5d7b6044846d4d to your computer and use it in GitHub Desktop.
Create a custom get_posts() for use in the genesis_sitemap_output() so you can show only specific categories or show all posts but not ones in the exclude parameter. See https://codex.wordpress.org/Template_Tags/get_posts
<?php
// don't include
/** ====================================================================================
* get posts for sitemap
* https://codex.wordpress.org/Template_Tags/get_posts
==================================================================================== **/
function christina_get_posts_for_sitemap() {
global $post;
$posts = get_posts('numberposts=50&offset=0&exclude=5,7'); //this example excludes posts 5 and 7
//Examples:
//$sitemap_post_list = get_posts('numberposts=50&offset=0&exclude=1646'); // exclude a post by ID, use commas between all the posts you want to EXCLUDE
//$sitemap_post_list = get_posts('numberposts=50&offset=0&category=5'); //show only a specific category by ID, use commas between the other ids you want to INCLUDE
$sitemap_post_list = '<ul>';
foreach ( $posts as $post ) :
setup_postdata( $post );
$sitemap_post_list = '<ul>';
foreach ( $posts as $post ) :
setup_postdata( $post );
$sitemap_post_list .= '<li>';
$sitemap_post_list .= '<a href="' . get_the_permalink() .'">';
$sitemap_post_list .= get_the_title();
$sitemap_post_list .= '</a>';
$sitemap_post_list .= '</li>';
endforeach;
$sitemap_post_list .= '</ul>';
return $sitemap_post_list;
wp_reset_postdata();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment