No plug-in realize WordPress theme pagination function

The use of fewer plug-ins, but it allows users to fully experience the theme of the function is really good theme, which is all the theme designer should consider.

By default WordPress flip page function is very weak, therefore, similar to the wp-pagenavi plugin page, almost WordPress blog plugin must be installed, and also a very high penetration plug-in.

The following paragraph lightweight functions, plus a few lines of css styles can completely replace the pagination plugin.

Specific method

First, add the following paragraph to the function code template theme 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;
         if(!$pages)
         {
             $pages = 1;
         }
     }   
 
     if(1 != $pages)
     {
         echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>« First</a>";
         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>‹ Previous</a>";
 
         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
             }
         }
 
         if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next ›</a>";  
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last »</a>";
         echo "</div>\n";
     }
}

Next, use the following code to replace the original default page template code or pagination plug-in code

<?php
    if (function_exists("pagination")) {
        pagination($additional_loop->max_num_pages);
    }
?>

Finally the following style code to the style.css in refresh the page, the page with the use of plug-ins to achieve the same effect.

.pagination {
    clear:both;
    padding:20px 0;
    position:relative;
    font-size:11px;
    line-height:13px;
}
 
.pagination span, .pagination a {
    display:block;
    float:left;
    margin: 2px 2px 2px 0;
    padding:6px 9px 5px 9px;
    text-decoration:none;
    width:auto;
    color:#fff;
    background: #555;
}
 
.pagination a:hover {
    color:#fff;
    background: #3279BB;
}
 
.pagination .current {
    padding:6px 9px 5px 9px;
    background: #3279BB;
    color:#fff;
}
0.00 avg. rating (0% score) - 0 votes