Solved

WordPress - Add pagination to a list of Child pages.

Posted on 2009-07-01
1
1,242 Views
Last Modified: 2012-08-13
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 -->

Open in new window

0
Comment
Question by:wattanabi2
1 Comment
 
LVL 3

Accepted Solution

by:
NovaRising earned 500 total points
ID: 24787258
You are going to have to manually limit the number of posts you want to display to a certain number.

http://www.wprecipes.com/how-to-define-how-many-post-to-display-per-page


This plugin is optional and can help you if you want numbers instead of next/previous.

http://www.catswhocode.com/blog/how-to-integrate-a-pagination-in-your-wordpress-theme


I pasted the code below that I think should work. You shouldn't have to add any "endif" tags or "endwhile" tags since you already have them. Let me know if I can help further.
For the First Step Find:

----------------------------------------
 

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

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

And Replace With:

-----------------------------------------

$page_num = $paged;

if ($pagenum='') $pagenum =1;

query_posts('page_id=' . $pageChild->ID . '&showposts=10&paged='.$page_num); ?>

               	<?php if (have_posts()) : ?>

		<?php while (have_posts()) : the_post(); ?>

Open in new window

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
This article will shed light on the latest trends when it comes to your resume building needs. For far too long, the traditional CV format has monopolized the recruitment market.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now