[wp-hackers] Access the total number of pages of a multipage post or page out of the loop

Mark Duncan wp-t31os at ntlworld.com
Fri Apr 30 02:43:58 UTC 2010

Inside the loop get the value of $numpages (global if necessary), and it 
should give you the total amount of pages in accordance with your usage 
of <!--nextpage--> for that post/page.

Tested on trunk, and returns the correct value for a paged post..

Hope that helps.

Aldo Latino wrote:
> Hi wp-hackers,
> In the title element of my pages I have this structure that displays the
> number of the current multipage page plus the total number of pages:
> «cat-name» Category Archive - Blog Name [this is the first page]
> «cat-name» Category Archive | Page 2 of 13 - Blog Name
> «cat-name» Category Archive | Page 11 of 13 - Blog Name
> and so on...
> The same structure is used on all archive pages, search pages, etc.
> The code successfully used is:
> if (is_category()) {
> echo '&laquo;'.single_cat_title('', false).'&raquo; Category Archive';
> if ($paged) { echo ' | Page '.$paged.' of '.$wp_query->max_num_pages;
> }
> The problem is on single and page pages where I'm not able to get the
> total number of pages. I tried:
> if ($page) { echo ' | Page '.$page.' of '.$numpages; }
> and
> if ($page) { echo ' | Page '.$page.' of '.count($pages); }
> but $numpages and $pages are active only during the loop.
> How can I access the total number of pages of a multipage post or page
> in the head section?

__________ Information from ESET NOD32 Antivirus, version of virus signature database 5073 (20100429) __________

The message was checked by ESET NOD32 Antivirus.


More information about the wp-hackers mailing list