2012
-
-
There’s something i have never really liked in WordPress, it’s the “older posts” / “previous posts” links. Simply because a site using this “pagination” method doesn’t give any information to the visitor about the number of published posts. I prefer having a nice pagination that clearly shows that there are “x” posts, it gives me an idea about the website i’m currently visiting. That’s why i’m going to explain in the above lines how to create a simple but nice pagination in just a few lines of code.
First of all you have to know something: WordPress core developers have nearly always a solution for us, and this is what i like in WordPress. There’s always a function, a bit of code on the codex, to help us creating great stuff. This is the case with the paginate_links() function. So, in the code above what we are doing is getting the total pages number that we put inside the $total variable. Then, we get the current page, and then the permalink format (don’t forget to set up a SEO friendly permalink structure). Just paste the PHP code where you want the pagination to appear and the CSS code inside your style.css file (in your theme directory), and that’s it ! You can view the result here or here!
Hey! My name is Rémi Corson, i'm a WordPress Expert Developer, i create high level themes and plugins, and i provide free stuff every week on this website!
2012-08-16 13:54:11
Hi!
It says “Can’t use function return value in write context in /wp-content/themes/testtheme/includes/template-tags.php on line 27″. That line is “if(empty(get_option(‘permalink_structure’))) {“
2012-08-17 00:19:25
That way it does not work with default permalinks.
I found out that this works with both (on WP 3.4.1)
if (get_option(‘permalink_structure’)) {
$format = ‘page/%#%/’;
}
else {
$format = ‘&paged=%#%’;
}
2012-08-16 14:47:09
I agree, the next page link is boring! Thanks for this post… I’ve been developing a theme from scratch and this will come in SO handy. Can’t wait to go try it out!!! Thanks again =D
2013-05-15 20:17:46
Hi Remi
I code this condition
if( get_option(‘permalink_structure’) == ‘/%postname%/’ )
because if permalink structure option is set to custom, I have a 404 error page when I click on page number links. The link generated was &paged=%#% instead of page/%#%/ which it’s expected.
Manu