WordPress post pagination without plugin has been explained in this case for users


Pagination in WordPress post without plugin has been explained in this article

Many users and specifically developers do not want to have extra additional plugins loaded up into their website for each and every function and hence take help of coding in that case.

Simple codes which can do functionality and no need of plugins in this case lead us to believe that one can easily add them and get rid of the extra plugins which cause slow down of the website since they load up in either header or footer.

Lesser plugins would mean that conflicting plugins would also result less and one would have to worry less about plugin updates in future as well.

Here are 2 methods which are simple codes given for someone to have pagination in WordPress post simply and easily.

WordPress post pagination without plugin method 1 using functions.php

if ( ! function_exists( 'post_pagination' ) ) :
   function post_pagination() {
     global $wp_query;
     $pager = 999999999; // need an unlikely integer
        echo paginate_links( array(
             'base' => str_replace( $pager, '%#%', esc_url( get_pagenum_link( $pager ) ) ),
             'format' => '?paged=%#%',
             'current' => max( 1, get_query_var('paged') ),
             'total' => $wp_query->max_num_pages
        ) );

One needs to use the function now wherever or in whichever template they want to display:

Number of posts can be selected from Settings>readings>Select number of posts to show. And thus the number of posts would be displayed as per your choice.

2nd method we are explaining for WordPress post pagination without plugin is for custom post types:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    'post_type' => 'post', // You can add a custom post type if you like
    'paged' => $paged,
    'posts_per_page' => 10 // limit of posts
if ( have_posts() ) :  while ( have_posts() ) : the_post();
     // post content goes here...
 else :
// no posts found message goes here...

Of course one would need to still stylize them once they have been displayed.

Some other developer also has written their code along with styles hope that one works for you so we will list it as method number 3 to display WordPress post pagination without plugin:

Add the following in functions.php file:

function pagination($pages = '', $range = 4)

     $showitems = ($range * 2)+1; 
     global $paged;
     if(empty($paged)) $paged = 1;
     if($pages == '')
         global $wp_query;
         $pages = $wp_query->max_num_pages;
             $pages = 1;
     if(1 != $pages)
         echo "


And then use this code in Style.css of your theme file:

.pagination {
padding:20px 0;
.pagination span, .pagination a {
margin: 2px 2px 2px 0;
padding:6px 9px 5px 9px;
background: #555;
.pagination a:hover{
background: #3279BB;
.pagination .current{
padding:6px 9px 5px 9px;
background: #3279BB;

Finally calling the pagination plugin in whichever template you want to use it:

} ?>

Hope this is useful for users.

In case one wants they can use WordPress pagination plugins as well.

Video Tutorial of this text:

About Shri Posts

Shri shares exciting WordPress themes, plugins and other WordPress related news for our viewers. He also posts selected WordPress developers interviews from time to time.

SKT Free Software Theme