Join WhatsApp ChannelJoin Now

Custom Pagination Add In WordPress

Hi,

Today, i we will show you custom pagination add in wordpress. This article will give you simple example of custom pagination add in wordpress. you will learn custom pagination add in wordpress.

In this example, I am telling you how you can set custom pagination without a plugin, we use this custom pagination in post and product. So let’s follow few step to create example of custom pagination add in wordpress.

Copy the code and add it to your functions.php file:

////////////////////pagination
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
        ) );
   }
endif;

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;
         if(!$pages)
         {
             $pages = 1;
         }
     }  
     if(1 != $pages)
     {
         echo "
Page ".$paged." of ".$pages."";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "« First";
         if($paged > 1 && $showitems < $pages) echo "‹ Previous";
 
        // for ($i=1; $i = $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "".$i."":"".$i."";
             }
        
 
         if ($paged < $pages && $showitems < $pages) echo "Next ›"; 
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "Last »";
         echo "
\n";
     }
}

You can get content by doing this function in your file:

post_pagination();

Recommended Posts