Skip to content

Instantly share code, notes, and snippets.

@neverything
Created June 17, 2015 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neverything/9520fdf7ea745eeb7c5d to your computer and use it in GitHub Desktop.
Save neverything/9520fdf7ea745eeb7c5d to your computer and use it in GitHub Desktop.
Drop this function in your functions.php without the initial <?php if there already is an opening tag in your functions.php.
<?php
function ict_bz_render_pages( $args = array(), $template = 'content-page' ) {
// Default values for the query
$defaults = array(
'post_type' => 'page',
'post_status' => 'publish',
'order' => 'ASC',
'orderby' => 'menu_order',
'posts_per_page' => 500,
);
// Merge default args and with the args provided by the function
$args = wp_parse_args( $args, $defaults );
// Returns WP_Query|WP_Error
$page_query = new WP_Query( $args );
// Fail early if possible
if ( is_wp_error( $page_query ) )
return false;
// See if we have the designated template file in the theme or parent theme
if ( '' == locate_template( $template . '.php' ) )
$template = 'content';
if ( $page_query->have_posts() ) {
while( $page_query->have_posts() ) : $page_query->the_post();
get_template_part( $template );
endwhile;
}
// Reset the post data set up by WP_Query
wp_reset_postdata();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment