WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] View multipage post in a single page (4 posts)

  1. mehulved
    Member
    Posted 1 year ago #

    I have a few posts which have multipage enabled. Thus, shows one post broken to various pages, which is what I need. But, I also want to give an option of reading the full article in a single page.
    I tried adding global $multipage outside the loop and then added $multipage = false; inside the loop. But, the post is still displays in multiple pages. Is there a way to allow an option the whole post to show up on one page only? I am trying to add the option by creating a link at the bottom of the page which adds ?multipage=false and using $_GET to check and set the $multipage value.
    So, the relevant part of my code looks like

    <?php
    global $multipage;
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    
    if ($_GET['multipage']=false) {
        $multipage = false;
    }
    the_content();
    endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
  2. mehulved
    Member
    Posted 1 year ago #

    OK. Figured out a way after reading some documents and some searching around. Still not sure if it's the perfect way.
    Here's my snippet of code for the purpose

    <?php
    get_header();
    global $multipage;
    global $post;
    
    if (have_posts()) : while (have_posts()) : the_post();
    
    echo 'singlepage=' . $_GET['read_single'] . '<br/>';
    
    $singlepage = $_GET['read_single'];
    echo '<h2>' . the_title() . '</h2>';
    if ( $singlepage == 1 ) {
        echo $post->post_content;
    }
    else {
        echo '<p>' . the_content() . '</p>';
        wp_link_pages();
    }
    
    endwhile; else: ?>
        <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif;
    
    get_footer();
    ?>
  3. Vincent Ballut
    Member
    Posted 1 year ago #

    After some research, it seems you just need to use echo $post->post_content; instead of the_content(); to display the full article.

  4. mehulved
    Member
    Posted 1 year ago #

    And to get proper formatting with $post->post_content we need to do what is mentioned here http://wordpress.org/support/topic/post-gtpost_content-with-formatting?replies=2

    So, finally the code looks like

    <?php
    get_header();
    global $multipage;
    global $post;
    
    if (have_posts()) : while (have_posts()) : the_post();
    
    echo 'singlepage=' . $_GET['read_single'] . '<br/>';
    
    $singlepage = $_GET['read_single'];
    echo '<h2>' . the_title() . '</h2>';
    if ( $singlepage == 1 ) {
        echo apply_filters('the_content', $post->post_content);
    }
    else {
        echo '<p>' . the_content() . '</p>';
        wp_link_pages();
    }
    
    endwhile; else: ?>
        <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif;
    
    get_footer();
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic