Solved

WordPress - Add pagination to a list of Child pages.

Posted on 2009-07-01
1
1,262 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
SEO can be a real minefield to navigate, but there are three simple ways to up your SEO game just be re-assessing your content output.
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

697 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