Pagination in wordpress custom theme

In order to add pagination to a WordPress theme, we need to build a function which will output previous and next post links at the bottom of the page, then add that to our template page. This is similar to the “Older Entries” and “Newer Entries” links that we saw above.

Goto to setting/reading and set number of post

http://localhost/wordpress/wp-admin/options-reading.php
index.php / postpage

<header> 
  <?php get_header(); ?> 
</header> 

<div class="card"> 
  <?php 
     if ( have_posts() ) : 
       while( have_posts() ) : the_post(); 
   ?> 

<h1> 
  <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </h1> 

  <a href="<?php the_permalink(); ?>"> <?php the_post_thumbnail( 'thumbnail' ); ?> </a> 

  <p><?php the_excerpt(); ?></p> 
 
  <?php endwhile; endif; ?> 
</div> 

wp_pagenavi(); // add this function

<footer> 
  <?php get_footer(); ?> 
</footer>
header.php

<?php wp_head(); ?>  // for addling all css files from plugins

<?php wp_footer(); ?> ( inside footer.php for including all js files from plugins )

Leave a Reply