Pagination is really important for any WordPress blog.It helps visitors to see posts by pages.Pagination divides your post in pages.Search Engines also love pagination of blog or website.

Today I will share about how to add Pagination in WordPress without plugin . To add a Pagination in your WordPress blog follow my instructions.

Also Read : WordPress Copy-Protect PN to Protect your Blog 

How to add Pagination in WordPress without plugin

First log in to your admin panel and go to Dashboard . Then go Appearance =>> Edit.

Then copy the code  ( given below) and paste it into function.php after this =>  ” ); ”

 

Also Read :Show Related Posts by category without plugin

CODE :

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)."'>&laquo; First</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; 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 &rsaquo;</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
echo "</div>\n";
}
}

After that Paste the code into style .css

.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;
}

Then go to index.php , if you find any code like this ( given below) delete it.

<div><?php next_posts_link('&laquo; Older Entries') ?></div>
<div><?php previous_posts_link('Newer Entries &raquo;') ?></div>

 

Remove code,Delete code

 

After removing the code in there paste this code

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

Then go to your homepage and i hope you will find a pagination .


Pagination in PerfectNeed