How To Add Numbered Page Navigation In Thesis Without Plugin

by Alamgir Hossain Shemul on 10 December, 2012. Updated 28 March, 2013

Page navigation is an essential tool for the visitor to run around your website. If you dont have an page navigation, I strongly suggest you to add one today. There are many plugin to do it. but it may not work. You need to override it. Although Extra plugin will make your site heavy. We know that the less plugin, the less burden on your site. So today i am going to show you how to Add Numbered Page Navigation In Thesis Without Plugin. You need access to custom.css and custom_functions.php.

How To Add Numbered Page Navigation In Thesis Without Plugin

This piece of code i am using for many days. i have found it in another blog,but unfortunately i have forgot it. Lets begin the show !

First download the Custom.css and custom-functions.php in case anything goes wrong.

Add the below code to custom_functions.php:

function numbered_page_nav($prelabel = '', $nxtlabel = '', $pages_to_show = 8, $always_show = false) {
	global $request, $posts_per_page, $wpdb, $paged;

	$custom_range = round($pages_to_show/2);
	if (!is_single()) {
		if(!is_category()) {
			preg_match('#FROM\s(.*)\sORDER BY#siU', $request, $matches);
		}
		else {
			preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches);
		}
		$blog_post_count = $matches[1];
		$numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $blog_post_count");
		$max_page = ceil($numposts /$posts_per_page);
		if(empty($paged)) {
			$paged = 1;
		}
		if($max_page > 1 || $always_show) {
			echo "<div class='page-nav'><div class='page-nav-intro'>Page $paged of $max_page</div>";
			if ($paged >= ($pages_to_show-2)) {
				echo '<div class="page-number"><a href="'.get_pagenum_link().'">1</a></div><div class="elipses">...</div>';
			}
			for($i = $paged - $custom_range; $i <= $paged + $custom_range; $i++) {
				if ($i >= 1 && $i <= $max_page) {
					if($i == $paged) {
						echo "<div class='current-page-number'>$i</div>";
					}
					else {
						echo '<div class="page-number"><a href="'.get_pagenum_link($i).'">'.$i.'</a></div>';
					}
				}
			}
			if (($paged+$custom_range) < ($max_page)) {
				echo '<div class="elipses">...</div><div class="page-number"><a href="'.get_pagenum_link($max_page).'">'.$max_page.'</a></div>';
			}
			echo "</div>";
		}
	}
}
remove_action('thesis_hook_after_content', 'thesis_post_navigation');
add_action('thesis_hook_after_content', 'numbered_page_nav');

 

Now Add the Below code to custom.css:

/* NUMBERED PAGE NAV */ .page-nav { font-size: 1.35em; font-weight: bold; margin: 1em 0; padding: 0; overflow: hidden; } .page-nav-intro { float: left; padding: .3em .5em; margin: 0 1em 1em 0; background: #efefef; border: .1em solid #ccc; } .page-number { float: left; padding: .3em .5em; margin: 0 .2em; background: #fff; border: .1em solid #ccc; } .current-page-number { float: left; padding: .3em .5em; margin: 0 .2em; background: #efefef; border: .1em solid #ccc; } .elipses { float: left; padding: .3em .2em; }

Ok ! Thats it. Now Save and upload these 2 files.

Code Backup

Revised on 28 March, 2013

This post is written by...

– He has written 194 wonderful posts on How To.

I am a Final year student of Rajshahi Medical College, Bangladesh. I am interested in Medical Technology, Internet and Web surfing. I love to Listen Music, Playing Games not only in Computer Also a Defender in Real Football. Connect him on Facebook,Twitter or I have a "Pediatric Medicine" Website.

{ 2 comments… read them below or add one }

Sujon Paul December 15, 2012 at 1:02 AM

Wrong code! My website crashed after applying it……

Reply

Alamgir Hossain Shemul December 15, 2012 at 1:58 AM

When you say Wrong boldly, my other visitors will get the wrong Information. I am using this code on two of my thesis site, including this one. Why dont you think, you may be used it incorrectly. Thanks.
Let me know where is the problem or use the Plugin method in my next post. I think that will be easier.
And one thing, site actually dont crush, if you make something wrong in custom_functions.php, site will not be shown until you correct it from Cpanel or Filezilla.

Reply

Leave a Comment

Please Use Real Name in Comments. Do not Spam, It will be Reported. You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code lang=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" extra="">

CAPTCHA Image
*

Previous post:

Next post: