WordPress: Check the Current Page Number CodeUnit 30 OCT 2012

If you are working on designing your own WordPress theme, then I’m pretty sure that at some point in time you’ve wanted to identify or check what page the user is currently viewing when working with loops.

To do this we need to make use of WordPress’ get_query_var function and look up a variable named ‘paged’, which as you guessed it, is a reference as to which page is currently being shown.

In practice:

$pageNumber = (get_query_var('paged')) ? get_query_var('paged') : 1; 

Obviously the page number can now be found in the $pageNumber variable.

Nifty.

About Craig Lotter

Software developer, husband and dad to two little girls. Writer behind An Exploring South African. I don't have time for myself any more.