Skip to content

Instantly share code, notes, and snippets.

@ihorduchenko
Created October 19, 2017 14:11
Show Gist options
  • Save ihorduchenko/f8bfb40c5f85db2ce06d06b3609cb9b9 to your computer and use it in GitHub Desktop.
Save ihorduchenko/f8bfb40c5f85db2ce06d06b3609cb9b9 to your computer and use it in GitHub Desktop.
Creating pagination on custom templates
<section class="news-list" data-aos-offset="0" data-aos-delay="2500"
data-aos="fade" data-aos-duration="1500">
<div class="news-list-mixer">
<?php
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$query_args = array(
'post_type' => 'news',
'order' => 'DESC',
'paged' => $paged,
'posts_per_page' => 10,
'orderby' => 'date'
);
$custom_query = new WP_Query( $query_args );
if ( $custom_query->have_posts() ) :
while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
<article class="news-block mix <?php $terms = get_the_terms( $post->ID, 'news_categories' );
foreach ( $terms as $term ) {
echo $term->slug . ' ';
} ?>">
<div class="container">
<div class="row">
<div class="news-block_image text-center col-md-6">
<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full', false ); ?>
<img src="<?php echo $src[0]; ?>" alt="<?php the_title(); ?>">
</div>
<div class="news-block_content col-md-6">
<div class="news-block_date mb-10 uppercase"><?php the_date( 'F j, Y' ); ?></div>
<h3 class="news-block_title mb-20"><?php the_title(); ?></h3>
<div class="news-block_text mb-25"><?php the_excerpt(); ?></div>
<a href="<?php the_permalink(); ?>" class="btn btn-dark btn-low">Read
More</a>
</div>
</div>
</div>
</article>
<?php endwhile; endif; ?>
<?php wp_reset_postdata(); ?>
</div>
<div class="container">
<div class="pagination d-flex">
<?php
$big = 999999999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var( 'paged' ) ),
'total' => $custom_query->max_num_pages,
'mid_size' => 5,
'prev_text' => __( 'Previous Page' ),
'next_text' => __( 'Next Page' ),
'type' => 'plain'
) ); ?>
</div>
</div>
</section>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment