Created
February 12, 2016 17:52
-
-
Save raselahmed7/7195c2eae0d552aae770 to your computer and use it in GitHub Desktop.
Custom post loop with pagination
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