
WP-PageNavi is definitely one of the most popular WordPress plugins and in fact, it is very useful. But did you know that since version 2.1, WordPress had a built-in function called paginate_links(), which can be used to create to paginate your blog without using any plugin? Today, let’s see how to use this handy function to create a pagination for your WordPress blog.






WPRecipes.com is hosted by VidaHost. Use our exclusive coupon CATSWHOCODE to get a 10% discount on hosting! 








11 Responses
Hi. This does not work for me. I tried on 2 blogs. I even tried with the default theme just in case. I paste it exactly where the old pagination links were, but just a blank page appears. WP version is 2.9.2. Did anyone made this code work?
It looks like there is an error
Can’t use function return value in write contex
I change
$format = empty( get_option(‘permalink_structure’) ) ? ‘&page=%#%’ : ‘page/%#%/’;
to
$format = get_option(‘permalink_structure’) ? ‘&page=%#%’ : ‘page/%#%/’;
and it works. Just want to know how I can highlight the current page.
Sorry, I know how to highlight the current page number now, should have read the document for paginate_links more carefully.
Thanks Sola, now it kind of works. At first I needed to change the single quotes because the ones in your comment give error. And the other thing is that it makes the link like this /page/2/ no matter if I am using another link structure.
Hi Nikolay, I have played around with the paginate_links function for a while after my last comment. It’s a really cool function, I think your problem has something to do with the $format.
$permalink_structure = get_option(‘permalink_structure’);
format = empty( $permalink_structure) ? ‘&page=%#%’ : ‘page/%#%/’;
pay attention to ‘page/%#%/’, this controls the link structure
Really cool tip, thanks for sharing it!
It works very well and looks much better than the WordPress link “Older Posts”.
Thanks!
This is a pretty cool tip! Thanks – I will implement this. Can the code be wrapped in divs for css?
Good, i like this.. This is a smart cool tip
Not working!
I got an error: Fatal error: Can’t use function return value in write context in this line – $format = empty( get_option(‘permalink_structure’) ) ? ‘&page=%#%’ : ‘page/%#%/’;
Look the comments from Sola to solve the error, Ken
change
$format = empty( get_option(‘permalink_structure’) ) ? ‘&page=%#%’ : ‘page/%#%/’;
to
$format = get_option(‘permalink_structure’) ? ‘&page=%#%’ : ‘page/%#%/’;
Trackbacks: