Query Child Of $Page

Current Release: 1.10 (download) – Released on May 26th 2008

What it does

This plugin allows you to run loops within your WordPress templates where you query for children of the current page.

How it works

The plugin adds an extra arguments to the list of arguments supported by query_posts().

The query argument `child_of` is used to add a WHERE to the database query to limit the pages returned to those with a post_page equal to the argument provided.
The query argument `child_limit` is used to limit the number of pages returned.
The query argument `child_offset` is used to offset the limiting to allow for pagination if required.

Requirements

This plugin has been tested with WordPress v2.8-beta and should work with all WordPress versions that support pages (v2.0 and later).

Usage Example

The following code is an example of what you could do to generate a list of the first 10 child pages from a parent page:

<div id="children">
<dl><?php query_posts('static=true&child_limit=10&child_of='.$id.'&order=ASC'); ?>
<?php if(have_posts()) : while (have_posts()) : the_post(); ?>
<dt><a href="<?php the_permalink();?>"><?php the_title();?>:</a><em><?php the_excerpt(); ?></em></dt>
<?php endwhile; endif; ?>
</dl></div>

More detailed usage examples can be found in this article “Searching for Children and Grandchildren

Download

The latest version of the plugin may be downloaded here: pjw-query-child-of.1.10.zip

97 thoughts on “Query Child Of $Page

  1. There’s a bug in the code — that’s why nobody can get it to work. To fix it, replace this:
    } else {
    return $where;
    }

    with this:

    }
    return $where;

  2. Stephen: Firstly – Gravatars should now be fixed I was using a very old version of skippys gravatars plugin which had caching and other features from back in the days when gravatar couldn’t handle the load.

    Secondly, that change will fix it – That is what the code I am running has in it! Somehow the code in the zip available for download is different from the code I am running!

  3. Pingback: Peter Westwood » Query Child Of $Page - update to make it work for anyone apart from me!

  4. Pingback: Nerdaphernalia » Automated Indexes

  5. Lyanna

    Hey there, this pluging worked phenominally, until I upgraded to WP 2.5 *cry*
    Is there any way to get it to work with the new WordPress? Thanks in advance.

  6. @Lyanna: The plugin works fine with WordPress 2.5 – I am using it on this site with WordPress 2.5 myself. Have you got version 0.02? There was a bug in version 0.01 which meant it didn’t actually work.

  7. Lyanna

    @Westi
    Sorry! Upon scrolling up I see I’ve ended up at the wrong plugin page. I came here via my wordpress plugin dashboard by clicking on the plugin name … I’m actually talking about the page excerpt plugin – apparently the wordpress interface links here instead of to the page excerpt plugin page 😀

    I’ll hop on over to the correct plugin page and make a new comment.

Comments are closed.