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 writing a code in the header that pertains to link rel='prev' and link rel='next' thing but I need to check if the post is multipage. I check out these global variables:

$numpages $multipage

However they don't work in header.php or outside the loop? Example code to verify in header (just a test, but it does not work):

<?php
global $wp_query;
global $numpages;
global $multipage;
If ($multipage) {
echo 'This is a multipage post';
} else {
echo 'This is not multipage';
}
?>

I am wondering how to do this, can somebody help me please? Thanks.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Just inspect the current post content for '<!--nextpage-->':

function wpse_check_multi_page()
{
    $num_pages    = substr_count(
        $GLOBALS['post']->post_content,
        '<!--nextpage-->'
    ) + 1;
    $current_page = get_query_var( 'page' );
    return array ( $num_pages, $current_page );
}

On page 2 of 3 that returns:

Array
(
    [0] => 3
    [1] => 2
)

On an unpaged post it returns:

Array
(
    [0] => 1
    [1] => 0
)
share|improve this answer
add comment

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.