Do You want to create a Custom Post Type loop with the Genesis core pagination? In this post I’m gonna show You how to do it.
1) Create a Custom Post Type and add some posts to it
You can create a Custom Post Type with code, or You can use a plugin like Custom Post Type UI to do it.
2) Create a new page named Pagination and leave it blank
3) Create a genesis template file named page-pagination.php and place this code into it
If You set the slug of the previous created page after the file name page.php -> page-pagination.php, You don’t need to specify the Template name: Pagination right after the opening php tag.
<?php // ========================================================================= // CUSTOM POST TYPE WITH PAGINATION // ========================================================================= function custom_loop_with_pagination() { global $post; $args = array( 'post_type' => 'books', //---YOUR CUSTOM POST TYPE 'posts_per_page' => 4, //---SET HOW MANY POSTS MUST BE SHOWN ON ONE PAGE 'paged' => get_query_var( 'paged' ) ); global $wp_query; $wp_query = new WP_Query( $args ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <article> <h2><?php the_title(); ?></h2> <?php the_excerpt(); ?> </article> <?php endwhile; do_action( 'genesis_after_endwhile' ); endif; wp_reset_query(); } add_action( 'genesis_loop', 'custom_loop_with_pagination' ); remove_action( 'genesis_loop', 'genesis_do_loop' ); genesis();
Leave a Reply