Created
June 17, 2015 12:16
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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