Skip to content

Instantly share code, notes, and snippets.

@diegoliv
Last active December 14, 2015 13:43
Show Gist options
  • Save diegoliv/2e2ce0048c29baec3619 to your computer and use it in GitHub Desktop.
Save diegoliv/2e2ce0048c29baec3619 to your computer and use it in GitHub Desktop.
Custom loop pagination in single post type template
<?php get_header(); ?>
<div class="container">
<div class="row">
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$disciplinas = new WP_Query( array(
'post_type' => 'disciplinas',
'posts_per_page' => 3,
'paged' => $paged
) );
?>
<?php if( $disciplinas->have_posts() ) : ?>
<?php while ( $disciplinas->have_posts() ) : $disciplinas->the_post(); ?>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-body">
<h3><?php the_title() ?></h3>
<a href="<?php the_permalink() ?>" class="btn btn-primary"><?php _e( 'Ver Disciplina' ) ?></a>
</div>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php previous_post_link( __( 'Prev' ), $disciplinas->max_num_pages ); ?>
<?php next_post_link( __( 'Next' ), $disciplinas->max_num_pages ); ?>
<?php wp_reset_postdata(); ?>
</div>
</div>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment