WordPress.org

Support

Support » How-To and Troubleshooting » If/Else child list for Custom Post Type single template

If/Else child list for Custom Post Type single template

  • Hi all,

    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 <?php post_class(); ?>" 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.

    Many thanks,

    Adam

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘If/Else child list for Custom Post Type single template’ is closed to new replies.
Skip to toolbar