Single Page View for Paginated Posts

Okay, so you know how you can break up a wordpress post by inserting the next-page/page break quicktag. Then, using the wp link pages function in your template, wordpress will generate page 1, 2, 3, etc. links for your now paginated post.

Great. But is there any way to put the post back together again? Think about all the online magazines and newspapers that break their articles into pages and then offer some variation on a “single page view.” Can you do that with WordPress? I spent the whole weekend trying to google a solution and came up with exactly nothing.

Related posts

Leave a Reply

1 comment

  1. Yes, it is possible, and I use it on my own site. Here it is in action: my Settings API post is paginated, but can viewed on a single page, using the “Single-Page View” link.

    First, you need to prepare a custom query variable, e.g. in functions.php, add the following:

    function cbnet_parameter_queryvars( $qvars ) {
        $qvars[] = 'all';
        return $qvars;
    }
    add_filter( 'query_vars', 'cbnet_parameter_queryvars' );
    

    Second, inside the Loop, you need to replace your basic call to the_content() with the following:

    global $wp_query;
    $no_pagination = false;
    if ( isset( $wp_query->query_vars['all'] ) ) {
        $no_pagination = $wp_query->query_vars['all'];
    }
    if( $no_pagination ) {
        echo apply_filters( 'the_content', $post->post_content ); 
        $page=$numpages+1;
    } else {
        the_content('Read the rest of this entry');
    }
    

    Then finally, you need to add a link to generate the single-page view, e.g. next to your “Permalink” and “Comments” links in your Post Meta:

    <?php 
    global $numpages;
    if ( is_singular() && $numpages > 1 ) { ?>
            <strong>|</strong> <a href="<?php echo add_query_arg( array( 'all' => '1'), get_permalink() ); ?>" title="single-page view">Single-Page View</a>
    <?php } ?>
    

    Now, when you clock the “Single-Page View” link, the entire post content will appear on a single page.

    Note: h/t to this WPORG support forum topic