0

I'm developing a site that involves a lot of long posts I'd like to break up using the nextpage quicktag. On the first page there's a large splash photo in the header that I'd like to disappear on subsequent pages—so I need some way of testing if the user is on the first page. I did find this code:

if ( isset($wp_query->query_vars['page'] ) )

But that seems to only works with default permalink settings. I need something that works with the Postname permalink setting. Any help is greatly appreciated.

0

As suggested by @s_ha_dum, you can check the value of page. The value is 1 when you're on the first page.

global $page;
if ( $page == 1 ) :
    // you're on the first page
endif;

But probably you need to check if the post is paginated first:

global $multipage;
if ( 0 !== $multipage ) :

    global $page;
    if ( $page == 1 ) :
        // you're on the first page
    endif;

endif;
0

I am not sure why your code doesn't work, but you should be able to check the page global. It should be a positive number on all but first page of a pages post. $page is NULL on the first page but set to an integer otherwise. The following should work, and does when I test it.

global $page;
if (empty ($page)) {
    echo 'first page';
}

... should work.

  • I'm afraid that didn't work. – Zachary Leven Jun 4 '15 at 16:40
  • This code is correct. I just tested it. If it is not working for you then something is breaking it. I don't know how to guess what. – s_ha_dum Jun 5 '15 at 5:38

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.