I recently worked on a project where the client wanted to add paging functionality to each of the custom post types I had created for the site build.
To accomplish this, I downloaded and installed the WP PageNavi plugin but quickly realized that I couldn’t just simply add the wp_pagenavi();
function and leave it at that.
After perusing the formus, I found a solution that worked for me on both custom post type archive pages using the WordPress Loop as well as WordPress templates using a custom WP Query.
If you are looking for how to add WP PageNavi to any post type archive page already using the WordPress Loop, you simply need to add the wp_pagenavi();
function immediately after the while closing curly brace and you should be good to go!
Things get a little trickier for page templates but nothing we can’t handle!
Basically you simply need to add the paged functionality into the new WP_Query
. For the wp_pagenavi();
function call, you also need to add a parameter for your custom query. Take a look at the code below to view how this should be setup.
I hope you found this as useful as I did! Let me know if this helped you out or if you need some help getting it set up properly. Thanks!
where i put the code?
Hi ajibarman,
You can use it wherever needed. I typically wind up using it in custom page templates myself.
Just wanted to give show some love with a big thank you! I’d been searching for quite some time trying to find a solution to custom post type pagination. Awesome!
Awesome Alex! Glad I could help you out! Pretty much everything I post on the site is the result of time spent searching for a solution. Posting here helps me to be able to refer to the solution I found and also help anyone else out looking for the solution. Glad this helped you out man!
Fine,
I have used, it is working fine
Se ganó el cielo, papi. Sí funciona. Gracias
Great Its work 🙂 Thanks
Glad it helped you Hina!
Thanks Jordan, But there seems a little issue with me, pagination is working fine but number of pages showing are constant like if i display posts_per_page’ => 5 pagination stops at 11 even though content is displayed only on first 4 pages, but if I add more content say more than 23 article then pagination doesn’t go beyond page 11 check out this URL http://examflip.com/january-2017-current-affairs/
Hi Avinash,
The first thing I would do is visit your Permalinks page.
Beyond that, I’m not quite sure what the issue would be without digging in a deeper.
Just to be clear, will this work with a wordpress “page”? I’d like to add the functionality to a page, not a post or list of posts. Basically i’m using wordpress as a static website with no blog.
Thanks.
Hi Steve, I’m not quite sure I understand. Are you trying to add paging to the “page” post type?
Yes. A single page, not post.
Is that possible?