<?php $populargb = new WP_Query('showposts=5' ); while ( $populargb->have_posts() ) { $populargb->the_post(); ?> <li> <a href="<?php the_permalink(); ?>"> <div class="blog__list__img"> <?php the_post_thumbnail(); ?> </div> <div class="blog__list__content"> <h2 class="blog__list__content__h2"><?php the_title() ?></h2> <p class="blog__list__content__description"><?= get_the_excerpt(); ?></p> <span class="blog__list__content__date"><?php the_time("j FY") ?></span> </div> </a> </li> <?php } ?> 

Good day. I have this code. And I tried to do pagination, but he didn’t remove it from me. Generally even page numbers. Tell me how to add pagination?

  • And what in this code is responsible for pagination? It just does not appear on its own! - eugene_v

1 answer 1

Look around this

 <?php // set the "paged" parameter (use 'page' if the query is on a static front page) $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; // the query $the_query = new WP_Query( 'cat=1&paged=' . $paged ); ?> <?php if ( $the_query->have_posts() ) : ?> <?php // the loop while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <?php the_title(); ?> <?php endwhile; ?> <?php // next_posts_link() usage with max_num_pages next_posts_link( 'Older Entries', $the_query->max_num_pages ); previous_posts_link( 'Newer Entries' ); ?> <?php // clean up after the query and pagination wp_reset_postdata(); ?> <?php else:  ?> <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> <?php endif; ?> 
  • Oh, from the phone somehow wrong, I will correct from the PC - eugene_v
  • Corrected already ... - KAGG Design
  • Thank you, it’s really inconvenient to insert a code from your phone - eugene_v