Last active
April 30, 2018 10:09
-
-
Save pixelstorm/2bd9ddcdad9c0cee5cdd8ac54e925336 to your computer and use it in GitHub Desktop.
paginaiton for custom post type
This file contains hidden or 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
//set up the loop, in this case we are looping through projects custom post type | |
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; | |
$project_query = new WP_Query( array( | |
'post_type' => 'project', | |
'posts_per_page' => 2, | |
'paged' => $paged | |
) ); | |
?> | |
//do the loop | |
<?php if ( $project_query->have_posts() ) : ?> | |
<?php while ( $project_query->have_posts() ) : $project_query->the_post(); | |
//output content | |
endwhile; ?> | |
//output pagination links | |
<?php $big = 999999999; // need an unlikely integer | |
echo paginate_links( array( | |
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ), | |
'format' => '?paged=%#%', | |
'type' => 'list', | |
'current' => max( 1, get_query_var('paged') ), | |
'total' => $project_query->max_num_pages | |
) ); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment