What is pagination
By default worpress shows links for next and previous posts. Older will show the ten previous posts and newer will show the next ten posts. It is desireable to add page numbers for posts, so that you know how many post pages are there and you can move to any desired page by one click. Pagination gives navigation ease plus a more professional look to your post loop. You must have seen pagination below post loop which looks like this,
How to add pagination to Post loop
There are two ways of adding pagination to post loops. One is through a plugin and the other is through writing some code in your wp_query.
Pagination Through Plugin
I have used a pagination plugin called “WP Page Numbers” . Its a nice plugin, it gives you few templates of pagination to work with. You can choose any of them to suit your theme colors. Below you can see the templates available within the plugin itself.
Pagination through Code
For displaying page number below a post loop, you have to do 3 things
- add the $paged parameter to wp_query
- write a custom page navigation function in functions.php
- create a file called paginate.php
- include the paginate.php after the loop to display page numbers
Lets start writing code. First open your functions.php and add this code