How to Create WordPress Pagination (page navigation) – No Plugin

Posted By Peach on February 18th, 2011

Today fusionpeach.com is keep growing up. I’ve already released 22 articles and now you can see only 10 latest posts. Therefore we need to add a new wordpress plugin or create it by ourself to help us access the old page. That’s sure, fusionpeach is my classroom. For knowledge I’ll try to do everything by my self. Let’s start!

1. Browse to you theme folder and open file “function.php” then paste the following code.

<?php
function fusion_pagination($pages = '', $range = 2){
$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 class='textpage'>".PAGE."</span>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='.get_pagenum_link($paged – 1).'>&lsaquo;</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)."'>&rsaquo;</a>";
if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</a>";
echo "</div>\n";
}
}

if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
?>

2. After we already have a function, we need to call it by open file “index.php” then write the function call below. (I placed it before the line for get wordpress sidebar tag)

<?php fusion_pagination($additional_loop-&gt;max_num_pages); ?>

3. Now we can access to the older ten post but we still need to decor it a bit by putting following CSS.

/* --------Pagination------------*/
.pagination {
clear: both;
padding: 0 20px;
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 span.textpage {
background: none;
color: #000;
}

.pagination .current{
padding: 6px 9px 5px 9px;
background: #3279BB;
color: #fff;
}

4. Repeat place the code that show in No.2 into “search.php” and “archive.php”. Here is the result.

Tags: , , ,

  • http://www.mmpersonalloans.com personal loan

    I would equal to add your journal to my blogroll gratify bowman me what mainstay should I use?

  • http://www.mmpersonalloans.com/ Dopalacze

    I would equal to add your journal to my blogroll gratify bowman me what mainstay should I use?

  • http://www.mmpersonalloans.com/ Dopalacze

    Thanks for good article. Hope to see more soon.

  • http://www.charteryachtcaribbean.com charter

    This website is pretty good. How was it made ?

  • http://www.charteryachtcaribbean.com virgin islands boat charter

    Have you considered adding some differing opinions to the article? I think it might enhance my understanding.

  • http://gossip.blogsanity.info Jeffery Guidroz

    Thanks for the great post!

  • Johnwakes

    doesnt work at all

  • http://blowmyfuse.com hot girls like me

    Not sure what is wrong but your code doesn’t appear to be working.

  • http://profiles.google.com/bradcamry brad camry

    These all post are really very great which can provides a different opinions it can be gratify to enhance the considering.

    article submissions

  • http://sorebuttcheeks.blogspot.com/ anabolic steroids blog

    great bit of php personally i hate having to use plugins.

    dianabol

  • http://www.seo-quotes.com.au seo quotes

    HI, 

    Your article is very helpful guys for users to Create WordPress Pagination.