Last Updated: November 15, 2017
·
249
· alexanderbiscajin

Use WP_Query to Create Pagination in WordPress

Add this code for Custom Query Pagination. You can follow the steps to create your own pagination in WordPress.

<?php
/**
* Template Name: Custom Page
*/
get_header(); ?>

<?php
$paged = ( getqueryvar( 'paged' ) ) ? getqueryvar( 'paged' ) : 1;
$args = array(
'postsperpage' => 4,
'paged' => $paged
);
$customquery = new WPQuery( $args );
?>
<!----start-------->
<div class="wrap">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">

<?php
while($customquery->haveposts()) :
$customquery->thepost();
?>
<div>
<ul>
<li>
<h3><a href="<?php thepermalink(); ?>" ><?php thetitle(); ?></a></h3>
<div>
<ul>
<div><a href="<?php thepermalink(); ?>"><?php thepostthumbnail('thumbnail'); ?></a></div>
</ul>
<ul>

<?php echo the

content(); ?></p>
</ul>
</div>
<div>
</li>
</ul>
</div> <!-- end blog posts -->
<?php endwhile; ?>
<?php if (functionexists("pagination")) {
pagination($custom
query->maxnumpages);
} ?>
</main><!-- #main -->
</div><!-- #primary -->
</div><!-- .wrap -->
<!----end-------->
<?php get_footer();

Reference: https://www.wpblog.com/use-wp_query-to-create-pagination/