Skip to content

Instantly share code, notes, and snippets.

@raselahmed7
Created February 12, 2016 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save raselahmed7/7195c2eae0d552aae770 to your computer and use it in GitHub Desktop.
Save raselahmed7/7195c2eae0d552aae770 to your computer and use it in GitHub Desktop.
Custom post loop with pagination
<?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