How do I determine if I’m on the very first page of pagination? I’m using WP_Pagenavi. I want to run a function only on the first page of the pagination. I checked the query_var ‘paged’, it’s set to 0 on this page, and then 2, 3 and so on in the later pages (1 is missing!)… Anyone knows a clean solution?
Thanks.
if you only want to know that you’re on the first page of a paginated page try
is_paged()
:I was looking for a simple way to determine whether or not to use the
posts_nav_link()
function and all solutions I found online were either too complex or unreliable. For example, many people suggested using the$paged
global variable, but I found that this variable returned the same value for the first page, even when the first page was the only page!So, I dug into the
wp-includes/link-template.php
file, and found that theposts_nav_link()
function simply outputs the return value of another function:Using this knowledge, we can create a simple and effective way to determine whether or not we need to add links to navigate between pages:
Originally posted on my blog here.