WordPress.org

Ready to get started?Download WordPress

Forums

Switch off pagination in posts? (6 posts)

  1. rrho
    Member
    Posted 9 years ago #

    I want to use <!--nextpage--> and the link_pages function to divide my posts into multiple pages since the posts are going to be quite long on the site I'm working on.

    However, I would like to offer readers the chance to see all of the post at once if they wish to - for example, to make a print-out. So, ideally, I should get something like this:

    Pages: 1 2 3 4 5 6 all

    I assume I will need a hack for this. Has anyone done this before? Otherwise, where would I have to look? Any help would be appreciated.

  2. Kafkaesqui

    Posted 9 years ago #

    Shelley did this about a year ago in her WordPress mods. It's mentioned here:

    http://weblog.burningbird.net/archives/2004/07/07/wordpress-modifications/6/

    The links no longer work, but a nicely worded request might get her to send you the appropriate code.

  3. davidchait
    Member
    Posted 9 years ago #

    My hack (which I may turn into a plugin):

    - in one of the main files (wp-config.php, or best is wp-blog-header.php), do something like:

    if (isset($_GET['print']))
    $force_single_page = true;

    Then, inside functions.php, in the function setup_postdata, add two things:
    1. global ref, add after the other global lines at top of function:
    global $force_single_page;
    2. the workhorse code, replace the two lines that look like:

    $pages = explode('<!--nextpage-->', $content);
    $numpages = count($pages);

    with

    if ($force_single_page)
    {
    $pages[0] = str_replace('<!--nextpage-->', '', $content);
    }
    else
    {
    $pages = explode('<!--nextpage-->', $content);
    }
    $numpages = count($pages);
    if ($numpages==1)
    $multipage = 0;

    That's basically the hack I use for my site. Also note that this code is designed to work with my CG-PageName plugin...

    -d
    CHAITGEAR

  4. Kafkaesqui

    Posted 9 years ago #

    I started thinking about this, and there is a completely template-based solution for it. First, change the_content() tag:

    <?php the_content(); ?>

    to this:

    <?php
    if(isset($_GET['page']) && 'all' == $_GET['page']) {
    $content = apply_filters('the_content', $post->post_content);
    echo $content;
    } else {
    the_content();
    }
    ?>

    Make this change in the single.php template. If your theme doesn't have one, make a copy of index.php and name it single.php. If you'd rather not use one, use index.php but alter the code to:

    <?php
    if(is_single() && isset($_GET['page']) && 'all' == $_GET['page']) {
    $content = apply_filters('the_content', $post->post_content);
    echo $content;
    } else {
    the_content();
    }
    ?>

    In summary this overrides any of the *tweaks* that are performed in get_the_content(), including its parsing of <!--nextpage--> for the purpose of pagination, but it still runs the regular text filters on your post's content before displaying it. You can use any value for the page GET. I used "all" only because it's in your example above.

    All you need is the link... You'll probably want to add it just after link_pages() (or wp_link_pages()) is called in the template. For custom permalinks, use:

    <a href="<?php the_permalink(); ?>all/">display entire post</a>

    (Can anyone verify that will *not* fail with custom permalinks?) And for default (query-type) permalinks:

    <a href="<?php the_permalink(); ?>?page=all">display entire post</a>

    Incorporating the link with the other page links would require editing the link_pages() function found in template-functions-post.php (wp-includes/ directory).

    EDIT: Checked myself, and the custom permalink example will fail (the mod_rewrite rules match againt 0-9, so no text value like 'all'). Any chance 0 will work as the "all" value? Hmm...

  5. davidchait
    Member
    Posted 9 years ago #

    hmmmm... I'd have to think if the skirting around the nextpage processing would nuke my CG-PageName plugin... my brain isn't functioning well enough at the moment to go look. ;)

    -d

  6. StewartUgelow
    Member
    Posted 8 years ago #

    Inspired by this thread, I wrote a plugin to do this.

    http://www.ugelow.com/2005/09/12/stewart-single-page-view/

Topic Closed

This topic has been closed to new replies.

About this Topic