A while back I wrote a tutorial over at Art of Blog explaining how to set up numbered page navigation for Thesis without using a plugin. While the code in that post is serviceable, it needs to be updated. If you are filtering any posts from your homepage, using custom templates, or using any custom taxonomy pages then the numbered nav gets a bit buggy.
Why use Numbered Page Navigation?
The main reason to use numbered page navigation is to improve the navigation of your blog. Anything you can do to up your page views will contribute to your blogging goals whether that’s gaining RSS subscribers, newsletter subscribers, selling ads or whatever else.
The New Code
This new code is compatible with every post index on your website! Blog index? Done. Search page? Check. Archive (tag, category, and author) pages? Yup. Custom taxonomies? Yessir! Got a custom loop? Filtering posts from any loop? You’re covered. This code is written to be incredibly flexible, and uses the same pagination method as Thesis itself!
Here’s the code to copy and paste into custom_functions.php.
function numbered_page_nav($prelabel = '', $nxtlabel = '', $pages_to_show = 8) {
global $wp_query, $paged;
$custom_range = round( $pages_to_show/2 );
$max_page = $wp_query->max_num_pages;
if( is_home() || is_archive() || is_search() || is_tax() ) {
if(!$paged) {
$paged = 1;
}
if($max_page > 1) { ?>
<ul class="numbered_nav"><li class="intro">Page <? echo $paged; ?> of <? echo $max_page; ?></li>
<? if( $paged >= ( $pages_to_show-2) ) { ?>
<li class="number"><a href="<? echo get_pagenum_link(); ?>">1</a></li><li class="ellipsis">...</li>
<? }
for( $i = $paged - $custom_range; $i <= $paged + $custom_range; $i++ ) {
if( $i >= 1 && $i <= $max_page ) {
if( $i == $paged ) { ?>
<li class="current_number"><? echo $i; ?></li>
<? }
else { ?>
<li class="number"><a href="<? echo get_pagenum_link($i); ?>"><? echo $i; ?></a></li>
<? }
}
}
if ( ($paged + $custom_range) < ($max_page) ) { ?>
<li class="ellipsis">...</li><li class="number"><a href="<? echo get_pagenum_link($max_page); ?>"><? echo $max_page; ?></a></li>
<? } ?>
</ul>
<? }
}
}
remove_action('thesis_hook_after_content', 'thesis_post_navigation');
add_action('thesis_hook_after_content', 'numbered_page_nav');
Adding Style
The CSS for this code will vary quite a bit, but here is the CSS I’m using here on Theme Big.
.numbered_nav { list-style-type: none; font-size: 10pt; margin: 0 0 2em; padding-right: 2em; overflow: hidden; color: #7e572e; text-shadow: 0px 1px #fff; font-weight: bold; }
.numbered_nav li { float: left; margin-right: .4em; overflow: hidden; }
.numbered_nav li a { display: block; padding: .5em .7em; color: #7e572e; background: #fefee8; }
.numbered_nav li a:hover { color: #cc661d; }
.numbered_nav li.number a:hover { background: #fefee8; color: #7e572e; text-shadow: 0px 1px #fff; border-bottom: .3em solid #4e973f; }
.numbered_nav li.intro { margin-right: 1.5em; background: #cc661d; color: #fefee8; text-shadow: 0px 1px #0c3144; padding: .5em .7em; }
.numbered_nav li.current_number { padding: .5em .7em; border-bottom: .3em solid #4e973f; background: #fefee8; }
.numbered_nav li.ellipsis { border: 0; padding: .3em 0; }
You’ll need to tweak this to match up to your own design, but this should give you a pretty good starting point. If you have any questions give me a shout in the comments and I’ll do my best to help you out!
Liked this post? Get free updates via RSS when we post or
{ 25 comments… read them below or add one }
Dear Adam,
so kind of you, thanks for this tutorial.
But when i use your breadcrumb, there is a message warning in my after post :
Warning: Missing argument 1 for is_taxonomy(), called in /home/h79381/public_html/wp-content/themes/thesis_18b1/custom/custom_functions.php on line 106 and defined in /home/h79381/public_html/wp-includes/deprecated.php on line 2515
how to fix it..
Please visit my blog (pancallok.com) and please submit your reply by leaving your comment on my first post. Thanks
Hi Pancallok,
Are you referring to breadcrumbs or to this page nav code? I visited your blog and your page nav appears to be working correctly. I don’t have access to your custom_functions.php so its impossible for me to say what the problem might be.
I can tell you I’ve used this code on over 20 sites now and never had one issue with it.
i mean, Page Navigation :D
there is a message warning in my single.php, don’t you see it?
here my custom-functions.php
http://pancallok.com/pancallok-custom-function.txt
single.php = my post content
Hey Adam,
is_taxonomy doesn’t quite do what you’d expect it to – it checks if a taxonomy exists. is_tax() should be used to check for the current page being a taxonomy archive.
You’ve always got the right answer! I’ll update accordingly.
Dear Adam, thanks for the tutorial. I use your code in my site. But the last line in the content (after the last post) is disappeared. How can I correct this?
Thanks Adam…It’s working just nice & fine at my blog….Appreciate it a lot……
I just wanted to thank you for writing this post. I’m heading over to my blog now to implement…
Thank you … thank you… thank you. I’m new to Thesis and spent all night playing, having fun and redesigning but when it came to actually allowing my readers to find other pages… well nobody had answers and if they did they were so complicated.
Your tutorial was simple and easy and added nicely to my site. I didn’t have to tweak anything! http://rantsnrascals.com see it here.
Thanks again so much. Oh and hey by the way. How did you create your little banners? Leave thoughts below and subscribe banner for rss below your posts? Those are neat!
Thanks Adam …Working great..you solved my big problem !!
Ok.. Adam Baird I am glad to know that your style content beautiful articles. From your articles i have successfully added my numbered page navigation.
Thanks…
Awesome. Thanks for this tutorial!
Beautiful blog design as well . . . bookmarked.
Big Thanks
well, this one worked like a charm. I tried to use a plugin and that was no use. But after this .. thanks man. I need to edit the css style a little bit.
Okay take a look at kujna.mk implemented it but as you can see it displays the pages in vertical not horizontal order, if you see the custom code then everything is pasted :/
Did you paste the css code?
Yes.
It was w3 total cache problem disabled it.
Tried and works for me. Thanks for such great and unique post !
Thanks for the updated code.
Noticed a bug
Right now the art of blog site has got 24 pages as of me posting this comments, please kindly navigate to
http://www.artofblog.com/page/19/
You will notice that there
Vielen lieben Dank!
Hat endlich super funktioniert bei mir.
I Love your blog great tutorial thank you so much Adam
Hi Adam. Thankyou very much.
Your pagination work perfectly in my thesis blog.