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. Brian: Not had a chance to come up with a solution to the paging issue yet. Been too busy working on WordPress 2.7 itself. As for why WordPress doesn’t have a child_of query var built in – mainly because I haven’t got round to turning this plugin into core code.

  2. LiZharD

    Nice plugin, works well on WP 2.6.5.
    One thing: i want to exclude from the result list the parent page. I get all child pages but there is also the parent page, i don’t need it in the list 😉
    Any ideas? Thanks

  3. LiZharD

    Problem fixed: in my file missing the $parent_page. Now all works as expected. Wow!

  4. Pingback: Blok » Umím do page vložit subpages!

  5. Derek Herman

    Has anyone gotten the ability to limit the pages returned to work? I really need this functionality, since I’m using this to query only the last two pages posted in my portfolio and show them on my custom home page. Anyone?

  6. Hi,
    Great Plugin!!! i’m running WP 2.7 and im having the same issue as DeeMo. after all the children pages are queried, it gives me the title and the content of the first subpage on the list. Anyone come up with a work around for this!?

    my query is php (‘static=true&posts_per_page=-1&child_of=’.$id.’&post_status=publish&order=ASC’)

    Thanks!

  7. @Derek: I believe you are up and running now. And thanks to your help with getting a limit working an updated version of the plugin will soon be available with limit support.

    @Matthew: I am not sure exactly what your problem is. It might help if you could send me more info about the query you are running and the template code you are using to output the results via my contact form.

  8. @Peter, yes everything is working great on wp 2.7 and being able to limit the output. Thanks for the huge help and push in the right direction, you should upload the new code so other people can benefit from being able to limit the pages returned. This should all be included in the core 😉 someday soon.

    Cheers

  9. DeeMo

    Still following this thread. If you get somewhere with our common problem, please post results.

  10. Pingback: WordPress Plugin Releases for 02/25 | Weblog Tools Collection

Comments are closed.