WordPress.org

Ready to get started?Download WordPress

Forums

Testing for paginated Pages (3 posts)

  1. Suffice
    Member
    Posted 2 years ago #

    I found these two examples:

    "You can use this code to check whether you're on the nth page in a Post or PAGE Page that has been divided into pages using the <!--nextpage--> QuickTag. This can be useful, for example, if you wish to display meta-data only on the first page of a post divided into several pages."

    <?php
    $paged = $wp_query->get( 'paged' );
    
    if ( ! $paged || $paged < 2 )
    {
        // This is not a paginated page (or it's simply the first page of a paginated page/post)
    
    }
    else
    {
       // This is a paginated page.
    
    }
    ?>
    <?php
    $paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : false;
    if ( $paged === false )
    {
        // This is not a paginated page (or it's simply the first page of a paginated page/post)
    
    }
    else
    {
       // This is a paginated page.
    
    }
    ?>

    Neither seem to detect whether or not there is another page or not--on the first page.

    What we've been trying to get at, is a way to show or hide a div container depending on if there is paginated Pages for the post.

    So; if isset($paged){
    <div></div>
    }

    Is what I was hoping just might work.

    We appreciate any help, thanks!

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    with the <!--nextpage--> you can check the value of $page or $numpages

    depending on if there is paginated Pages for the post.

    for instance:
    if($numpages > 1) { }
    will check if the post/page has 'nextpages'

  3. Suffice
    Member
    Posted 2 years ago #

    Thanks, that really worked out.

Topic Closed

This topic has been closed to new replies.

About this Topic