Last active
October 13, 2017 09:44
-
-
Save asufian97/8ad8b885060cae8b89948012feabe27e to your computer and use it in GitHub Desktop.
custom-post-loop-with-pagination.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 | |
global $paged; | |
$posts_per_page = 9; | |
$settings = array( | |
'showposts' => $posts_per_page, | |
'post_type' => 'portfolio', | |
'orderby' => 'menu_order', | |
'order' => 'ASC', | |
'paged' => $paged) | |
); | |
$total_found_posts = $post_query->found_posts; | |
$total_page = ceil($total_found_posts / $posts_per_page); | |
while($post_query->have_posts()) : $post_query->the_post(); | |
// Your single post | |
endwhile; | |
if( function_exists('wp_pagenavi') ) { | |
echo ' '.wp_pagenavi(array('query' => $post_query, 'echo' => false)).' '; | |
} else { | |
echo '<span class="nav-prev">'.previous_posts_link( 'Previous Posts' ).'</span> <span class="nav-next">'.next_posts_link( 'Next Posts' , $total_page ).'</span>'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment