Forums

[resolved] Print out all pages of my site (7 posts)

  1. epdahl90wp
    Member
    Posted 11 months ago #

    I need to be able to print out all of the pages of my blog to create a physical user manual for the online counterpart I'm developing for a client. I can go in and print each page individually but with 60 separate pages it's time consuming for the user. I've seen other people talk about creating a template that calls all of the content from the other pages onto one page. That would work for me if I could get it to work.
    Going off of http://wordpress.org/support/topic/print-out-all-pages?replies=3 I dropped their code into a template but it only displays a few random pages and not in any order.

    <?php
    	query_posts('post_type=page');
    	if (have_posts()) : while (have_posts()) : the_post();
    ?>
    
    <div class="postWrapper" id="post-<?php the_ID(); ?>">
    	<h3 class="postTitle"><?php the_title(); ?></h3>
        <div class="post">
        <?php the_content(__('(more...)')); ?>
        </div>
    </div>
    <?php endwhile; else: ?>
    
    <p>Sorry, no pages matched your criteria.</p>
    
    <?php endif; ?>

    I'm wondering if there is a way to edit this code to make it include all 60 pages and display them in order.

  2. MichaelH
    Volunteer
    Posted 11 months ago #

    Look at the 'order'and the 'posts_per_page' arguments in
    http://codex.wordpress.org/Class_Reference/WP_Query for something like:

    query_posts('post_type=page&order=name&posts_per_page=900&post_status=publish');
  3. epdahl90wp
    Member
    Posted 11 months ago #

    Thanks that pointed me in the right direction. Here is what I have now.

    <?php
    	query_posts('post_type=page&orderby=parent&order=asc&posts_per_page=900&post_status=publish');
    	if (have_posts()) : while (have_posts()) : the_post();
    ?>
    
    <div class="postWrapper" id="post-<?php the_ID(); ?>">
    	<h3 class="postTitle"><?php the_title(); ?></h3>
        <div class="post">
        <?php the_content(__('(more...)')); ?>
        </div>
    </div>
    <?php endwhile; else: ?>
    
    <p>Sorry, no pages matched your criteria.</p>
    
    <?php endif; ?>

    I tried to order by menu_order but since the parent pages are on their own menu_order number and the child pages all have their own numbers it reads it as having ten different pages with menu_order 1 instead of respecting the parent structure. Currently it's using the orderby "parent" command which groups up the child pages correctly but doesn't group the parent page with them. If there is a better way to order this let me know.

    The other idea I had is to change the menu_order on all the pages and number them 1-45 for each page. The problem with this is if I decide to add a page down the line I have to change every page after it in the sequence. This would make the orderby menu_order command work though.

    Last question - I need to exclude the "All pages" page from the list along with a few others. I can't figure out how to exclude multiple page id numbers.

  4. MichaelH
    Volunteer
    Posted 11 months ago #

    Didn't test but something like this would exclude pages with the ids of 2,5,12,14,20:

    $args = array(
      'post_type' => array( 'page' ),
      'post_status' => array( 'publish' ),
      'orderby' => 'parent',
      'order' => 'asc',
      'posts_per_page' => 900,
      'post__not_in' => array( 2, 5, 12, 14, 20 )
    );
    query_posts( $args );
  5. epdahl90wp
    Member
    Posted 11 months ago #

    Yes this works great. Just want to post the full code up if anyone else needs it in the future.

    <?php
    
    $args = array(
      'post_type' => array( 'page' ),
      'post_status' => array( 'publish' ),
      'orderby' => 'parent',
      'order' => 'asc',
      'posts_per_page' => 900,
      'post__not_in' => array( 181, 21, )
    );
    query_posts( $args );
    
    	if (have_posts()) : while (have_posts()) : the_post();
    ?>
    
    <div class="postWrapper" id="post-<?php the_ID(); ?>">
    	<h3 class="postTitle"><?php the_title(); ?></h3>
        <div class="post">
        <?php the_content(__('(more...)')); ?>
        </div>
    </div>
    <?php endwhile; else: ?>
    
    <p>Sorry, no pages matched your criteria.</p>
    
    <?php endif; ?>

    The only problem is that it is now displaying the words "Auto Draft" as a h3 post title after all of the main parent pages. Not sure where this is coming from or why it's suddenly showing up.

  6. MichaelH
    Volunteer
    Posted 11 months ago #

    See what happens if you use a new query--change

    query_posts( $args );
    if (have_posts()) : while (have_posts()) : the_post();

    to

    $my_query = new WP_Query($args);
    if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post();

    See The Loop for examples

  7. epdahl90wp
    Member
    Posted 11 months ago #

    I tried the new code and it produced nothing different. However upon inspecting the code in my browser I saw that it was coming from page 163 so I simply added it to the post__not_in array and it's gone. Couldn't find what that page was but doesn't matter if I can't see it.
    Thanks for all of your help you've been great!

Reply

You must log in to post.

About this Topic