Create custom wordpress page navi

Try this one
Paste the following code in function.php

<?php
#Page Navi

function page_navi($before = ”, $after = ”) {
global $wpdb, $wp_query;

$request = $wp_query->request;
$posts_per_page = intval(get_query_var(‘posts_per_page’));
$paged = intval(get_query_var(‘paged’));
$numposts = $wp_query->found_posts;
$max_page = $wp_query->max_num_pages;

if(empty($paged) || $paged == 0) {
$paged = 1;
}
$pages_to_show = 5;
$pages_to_show_minus_1 = $pages_to_show-1;
$half_page_start = floor($pages_to_show_minus_1/2);
$half_page_end = ceil($pages_to_show_minus_1/2);
$start_page = $paged – $half_page_start;
if($start_page <= 0) {
$start_page = 1;
}
$end_page = $paged + $half_page_end;
if(($end_page – $start_page) != $pages_to_show_minus_1) {
$end_page = $start_page + $pages_to_show_minus_1;
}
if($end_page > $max_page) {
$start_page = $max_page – $pages_to_show_minus_1;
$end_page = $max_page;
}
if($start_page <= 0) {
$start_page = 1;
}

echo $before.'<center><div class=”page_navi”>’.”\n”;
if ($start_page >= 2 && $pages_to_show < $max_page) {
$first_page_text = “First”;
echo ‘<a href=”‘.get_pagenum_link().'” title=”‘.$first_page_text.'”>’.$first_page_text.'</a>’;
}
previous_posts_link(‘&laquo;’);
for($i = $start_page; $i  <= $end_page; $i++) {
if($i == $paged) {
echo ‘<span class=”current”>’.$i.'</span>’;
} else {
echo ‘<a href=”‘.get_pagenum_link($i).'”>’.$i.'</a>’;
}
}
next_posts_link(‘&raquo;’);
if ($end_page < $max_page) {
$last_page_text = “Last”;
echo ‘<a href=”‘.get_pagenum_link($max_page).'” title=”‘.$last_page_text.'”>’.$last_page_text.'</a>’;
}
echo ‘</div></center>’.$after.”\n”;
}
?>

cal the following function where ever you want

 <?php page_navi(); ?>

use the following css for styling

.page_navi{padding:10px 0 10px 10px;}
.page_navi a,.page_navi a:link,.page_navi a:visited{text-decoration:none;border:1px solid #ccc;color:#2b74b4;background-color:#fff;font-weight:700;margin:2px;padding:2px 4px;}
.page_navi a:active,.page_navi a:hover{text-decoration:none;border:1px solid #2b74b4;color:#fff;background-color:#0F0;margin:2px;padding:2px 4px;}
.page_navi span.current{font-weight:700;border:1px solid #2b74b4;color:#fff;background-color:#03C;margin:2px;padding:2px 4px;}
Advertisements
  1. I enjoy reading through a post that can make people think.

    Also, thanks for permitting me to comment!

  2. I do agree with all of the ideas you have presented in your post.
    They’re very convincing and will certainly work. Nonetheless, the posts are very short for newbies. Could you please extend them a little from next time? Thank you for the post.

  3. Hi Dear, are you genuinely visiting this web page on a
    regular basis, if so after that you will without doubt obtain
    nice experience.

  4. You need to take part in a contest for one of the greatest
    websites on the internet. I am going to highly recommend this blog!

  5. Appreciating the persistence you put into your website and detailed information you present.

    It’s great to come across a blog every once in a while that isn’t the same old rehashed information.
    Fantastic read! I’ve saved your site and I’m including your RSS feeds to my Google account.

  6. I hardly leave responses, but i did some searching and wound up here Create
    custom wordpress page navi | shivawebs. And I actually
    do have 2 questions for you if it’s allright. Is it just me or does it look like a few of the remarks come across like they are left by brain dead visitors? 😛 And, if you are writing at additional online social sites, I’d like to follow everything new
    you have to post. Could you list of every one of your shared pages like your linkedin profile, Facebook page or twitter
    feed?

    • signs of bladder cancer
    • July 12th, 2013

    Seriously loads of good information.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: