Skip to content

Instantly share code, notes, and snippets.

@evanfraser
Last active February 14, 2018 17:33
Show Gist options
  • Save evanfraser/04a11d0ed39aacc6546c361f28f473e4 to your computer and use it in GitHub Desktop.
Save evanfraser/04a11d0ed39aacc6546c361f28f473e4 to your computer and use it in GitHub Desktop.
WordPress Page Sitemap Shortcode
<?php
/**
* Page Sitemap
* [page_sitemap title="" class=""]
*/
function yourfunction_page_sitemap($atts) {
ob_start();
extract( shortcode_atts( array(
'title' => '',
'class' => ''
), $atts ) );
$pages = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_status' => 'publish',
'orderby' => 'title',
'order' => 'ASC',
);
$get_recent_pages = new WP_Query( $pages );
$remove = explode(',', $remove);
$remove = array_filter(array_map('trim', $remove)); ?>
<div class="page-sitemap <?php if($class) { echo $class; }?>">
<?php if($title) { echo'<h2>'.$title.'</h2>';} ?>
<ul>
<?php while ($get_recent_pages->have_posts()) : $get_recent_pages->the_post(); ?>
<li>
<a href="<?php echo get_permalink($post->ID); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; wp_reset_query(); ?>
</ul>
</div> <?php
$result = ob_get_contents(); // get everything in to $result variable
ob_end_clean();
return $result;
}
add_shortcode( 'page_sitemap', 'yourfunction_page_sitemap' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment