Skip to content

Instantly share code, notes, and snippets.

@barbwiredmedia
Created March 26, 2014 17:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barbwiredmedia/9788302 to your computer and use it in GitHub Desktop.
Save barbwiredmedia/9788302 to your computer and use it in GitHub Desktop.
Wordpress Pagenavi Enable pagination for custom post types with a loop or wpquery
<?php
// Must have wp_pagenavi plugin installed. Custom Post Type names can not clash with page names or 404's will occur on /page/#/ (Utilize Custom Rewrite Slug in CPT)
// The press release loop
$the_press = new WP_Query(array('post_type' => 'press-releases','posts_per_page' => 10,'paged'=> get_query_var('paged') ));
// The Loop
while ($the_press->have_posts()) : $the_press->the_post();
?>
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
<p><a href="<?php echo the_permalink(); ?>" >Read More</a></p>
<?php endwhile; ?>
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(array('query'=> $the_press));} ?>
<?php wp_reset_postdata();?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment