## Get the Current Page Number

Question

In a situation where one has 20 posts per page. I would like to get the current page number in order to make some nice page links at the bottom. How do you get the current page. I tried this

<?php echo '(Page '.$page.' of '.$numpages.')'; ?>


and it just says page 1 of 1 on every page.

Any ideas,

Marvellous

in progress 0
11 years 2011-03-18T08:16:23-05:00 0 Answer 80 views 0

1. When WordPress is using pagination like this, there’s a query variable $paged that it keys on. So page 1 is $paged=1 and page 15 is $paged=15. You can get the value of this variable with the following code: $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$total_post_count = wp_count_posts();$published_post_count = $total_post_count->publish;$total_pages = ceil( $published_post_count /$posts_per_page );

I haven’t tested this yet, but you might need to fetch $posts_per_page the same way you fetched $paged (using get_query_var()).