WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to add a feature to my 'Services' custom post type single template that displays one thing if the post type has one or more child post types and another thing if it doesn't. So far I've come up with this, however it doesn't seem to work as expected:

$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); ?>
<?php if ($children): ?>

<div class="two-column align-left spacer">
<?php echo $children; ?>

<article class="four-column spacer align-left <?php post_class(); ?>"id="post-<?php the_ID(); ?>" role="article">

<?php the_content(); ?>


<?php else : ?>

<article class="six-column spacer align-left" id="post-<?php the_ID(); ?>" role="article">

<?php the_content(); ?>


<?php endif; ?>

Can anyone help me and point me in the right direction please? I have set up the Services post type to hierarchical => true and capability_type => post (and have tried page) but still no luck.

Obviously the code above needs to sit within the standard page loop. Does this mean I need to use query_posts instead?

Many thanks,


share|improve this question

If you're using custom post types then you're going to need to create a custom loop.

<?php $loop = new WP_Query( array( 'post_type' => 'services', 'posts_per_page' => 5) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php endwhile; ?>
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.