WordPress.org

Ready to get started?Download WordPress

Forums

If/Else child list for Custom Post Type single template (2 posts)

  1. flint_and_tinder
    Member
    Posted 2 years ago #

    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

  2. flint_and_tinder
    Member
    Posted 2 years ago #

    I'm not sure is this is relevant but the code above is all placed (and needs to work)within the page loop.

Topic Closed

This topic has been closed to new replies.

About this Topic