Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to find a way to get the current page number of an article that has been splitted into several pages with the use of:

<!-- nextpage -->

There is an example that can be found here: http://codex.wordpress.org/Conditional_Tags#Testing_for_paginated_Pages

But this doesn't work for me – it always returns 0:

$paged = $wp_query->get( 'paged' );
echo $paged;

Any idea? Thank you!

share|improve this question
    
If one of the answers helps you, select it as the answer please. –  hakre Jul 8 '11 at 14:37

2 Answers 2

up vote 4 down vote accepted

For multi-page posts:

  • The $page global variable returns the current page of a multi-page post.
  • The $numpages global variable returns the total number of pages in a multi-page post.

For paginated archive index pages:

  • The $paged global variable returns the current page number of a paginated archive index.

To use any of these variables, simply globalize them first:

global $page;

echo 'The current page number of this post is ' . $page . '.';
share|improve this answer

There you go:

$queryVars = $wp_query->query_vars;
    $pageNum = ($queryVars[page]);

    if($pageNum) { 
        echo "Page n&deg;" . $pageNum; 
    } else { 
        echo "Page n&deg;1";
    }

Tested with wp 3.2 with basic permalinks and custom.

Edit: Didn't see Chip Bennett's answer wich is smaller.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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