5

I have a custom post type that I want to display the page you are on and how many pages total in this manner "Page 3 of 5" (meaning you are on page 3 of a 5 page post). These don't have to be links, just plain text numbers.

I'd still like to keep the standard function of the wp_page_links parameter "next_or_number" set to "next", but add this other page indicator.

I've tried experimenting with making my own funciton with some of the variables in the wp_page_links function on line 567 of the post-template.php file but I didn't get anywhere.

7

The current / total page count is set up by setup_postdata() which runs at the beginning of the loop. So, if you're in the loop, all you have to do is this:

global $page, $numpages;
echo "Page $page of $numpages";

If you need to do that outside of the loop, do this first:

global $page, $post, $numpages;
// This next line is optional: sets a new global $post variable
$post = get_post(123);
setup_postdata($post);
echo "Page $page of $numpages";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.