Solved

WordPress - Add pagination to a list of Child pages.

Posted on 2009-07-01
1
1,252 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
In this blog, I will share you some basic tips for content marketing and to rank your website on Google.
The viewer will learn how to count occurrences of each item in an array.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

809 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