Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

<?php
if($post->post_parent)
$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">
<ul>
<?php echo $children; ?>
</ul>
</div>

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

<?php the_content(); ?>

</article>

<?php else : ?>

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

<?php the_content(); ?>

</article> 

<?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,

Adam

share|improve this question

1 Answer 1

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(); ?>
    POST HERE
<?php endwhile; ?>
share|improve this answer

Your Answer

 
discard

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.