WordPress.org

Forums

Add pagination to list of child pages (3 posts)

  1. grego3781
    Member
    Posted 5 years ago #

    Hello,

    I have a page where I'm pulling a list of child page titles/excerpts for that particular page. There are around 30 child pages for this particular page so I just want to display 10 child page titles/excerpts at a time with "Previous" and "Next" navigation buttons at the bottom of the page. The code listed below works fine but displays ALL of the child pages. Any Assistance is greatly appreciated.

    Thanks

    <!-- Start Code -->
    <?php
    $pageChildren = get_pages('child_of=' . $post->ID . '&exclude=' . $exclude_page );
    if ( $pageChildren ) {
    foreach ( $pageChildren as $pageChild ) {
    $pageChild->post_title.'</h2>';

    query_posts('page_id=' . $pageChild->ID);

    if (have_posts()) : while (have_posts()) : the_post(); ?>

    <div class="post" id="post-<?php the_ID(); ?>">
    <h2><?php the_title(); ?></h2>
    <div class="entry">
    <?php the_excerpt('<p class="serif">Read the rest of this page »</p>'); ?>

    <?php wp_link_pages(array('before' => '<p>Pages: ', 'after' => '</p>', 'next_or_number' => 'number')); ?>

    </div>

    </div>
    <?php endwhile; endif; ?>

    <?php
    }
    }
    ?>
    <!-- End Code -->

  2. rosebean
    Member
    Posted 4 years ago #

    Would love an answer to this as well. Thanks for any help.

  3. vtxyzzy
    Member
    Posted 4 years ago #

    This works in the default theme:

    <!-- Start Code -->
    <?php
    $postIDs = array();
    $pageChildren = get_pages('child_of=' . $post->ID . '&exclude=' . $exclude_page );
    if ( $pageChildren ) {
      foreach ( $pageChildren as $pageChild ) {
        $postIDs[] = $pageChild->ID;
      }
      $paged = (intval(get_query_var('paged'))) ? intval(get_query_var('paged')) : 1;
      $args = array(
        'post_type' => 'page',
        'paged' => $paged,
        'post__in' => $postIDs,
        'posts_per_page' => 10
                    );
      query_posts($args);
    
      if (have_posts()) : while (have_posts()) : the_post(); ?>
    
        <div class="post" id="post-<?php the_ID(); ?>">
        <h2><?php the_title(); ?></h2>
        <div class="entry">
          <?php the_excerpt('<p class="serif">Read the rest of this page ยป</p>'); ?>
    
          <?php wp_link_pages(array('before' => '<p>Pages: ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
        </div>
    
      </div>
      <?php endwhile; ?>
      <div class="navigation">
        <div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
        <div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
      </div>
    
    <?php endif; ?>
    
    <?php } ?>
    <!-- End Code -->

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags