Posted By

depiction on 06/06/12


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ignacio


WordPress Display Custom Posts with Pagination


 / Published in: PHP
 

URL: http://wordpress.org/support/topic/custom-post-type-taxonomy-pagination

Important: In WordPress, a page name and custom post type can't have the same name. If the below loop doesn't work, check to make sure they are different! Also, this assumes WP Page-Navi is installed and active.

  1. <h1><?php the_title(); ?></h1>
  2.  
  3. <?php the_content(); ?><br /><br />
  4.  
  5. <?php $i = 0; ?>
  6. <?php $loop = new WP_Query( array( 'post_type' => 'testimonial', 'orderby'=> date, 'paged' => get_query_var( 'paged' ), 'posts_per_page' => 5 ) ); ?>
  7.  
  8. <?php
  9. if ( function_exists( 'wp_pagenavi' ) ) {
  10. wp_pagenavi( array( 'query' => $loop ) );
  11. wp_reset_postdata();
  12. }
  13. ?>
  14.  
  15. <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
  16. <div class="testimonial-block">
  17. <?php
  18. $authorpic = get('testimonial_info_image');
  19. $authortitle = get('testimonial_info_title_company');
  20. ?>
  21.  
  22. <?php if ($authorpic != NULL) { ?><img src="<?php echo $authorpic; ?>" alt="person" class="testimonial-pic" /><?php } ?>
  23. <?php the_content(); ?>
  24.  
  25. <strong><?php the_title(); ?><br />
  26. <?php if ($authortitle != NULL) { ?><br /><?php echo $authortitle; ?><?php } ?></strong>
  27. <small><?php echo date("m\/d\/y"); ?></small>
  28. </div>
  29.  
  30. <?php $i++; endwhile; ?>
  31.  
  32. <div class="clear"><br /><br /></div>
  33. <?php
  34. if ( function_exists( 'wp_pagenavi' ) ) {
  35. wp_pagenavi( array( 'query' => $loop ) );
  36. wp_reset_postdata();
  37. }
  38. ?>

Report this snippet  

You need to login to post a comment.