afsarwebdev

wp-pagination-custom-post

Jul 30th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. //Custom post type with pagination
  2. // Reference link for first one https://stackoverflow.com/questions/15524195/wordpress-custom-post-page-with-pagination
  3. <?php
  4. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  5. $ic_gallery= new WP_Query(array(
  6. 'post_type'=>'gallery',
  7. 'posts_per_page' => 12,
  8. 'paged' => $paged,
  9. ));
  10. if($ic_gallery->have_posts()) : while($ic_gallery->have_posts()) : $ic_gallery->the_post();
  11. ?>
  12. <div class="ic-single-g-item">
  13. <?php the_post_thumbnail('gallery'); ?>
  14. <div class="ic-title-n-cat">
  15. <h3><?php the_title(); ?></h3>
  16. <span><?php the_content(); ?></span>
  17. </div>
  18. </div>
  19.  
  20.  
  21. <?php endwhile; ?>
  22. <div class="ic-gallery-navigation">
  23.  
  24. <?php
  25. $total_pages = $ic_gallery->max_num_pages;
  26.  
  27. if ($total_pages > 1){
  28. $current_page = max(1, get_query_var('paged'));
  29. echo paginate_links(array(
  30. 'base' => get_pagenum_link(1) . '%_%',
  31. 'format' => '/page/%#%',
  32. 'current' => $current_page,
  33. 'total' => $total_pages,
  34. 'prev_text' => __('Previous'),
  35. 'next_text' => __('Next'),
  36. ));
  37. }
  38. ?>
  39. </div>
  40.  
  41. <?php else :?>
  42.  
  43. <h1 style="color: red; padding: 30px; text-align: center;"><?php _e("Sorry no posts found, please go to dashboard and post from 'Team Member' menu"); ?></h1>
  44. <?php endif; wp_reset_query(); ?>
Add Comment
Please, Sign In to add comment