PHP to display div only for parent posts

I have two types of portfolio posts: parent posts and child posts. When displaying a single post that is a parent, I want this to display:

                <div class="col-1 art-singles art-controls">
                  <?php next_post_link('%link', '←'); ?>  &nbsp;
                    <a href="<?php get_home_url(); ?>/work" alt="all work">All</a>&nbsp;  
                  <?php previous_post_link('%link', '→'); ?>
                  <a href="#" alt="enlarge image" class="enlarge-it"><p style="text-transform: none;">Enlarge</p></a>
                </div>

When on a child post, I want a slight variation of the above to display.

Right now, I’m using this to display the menu on ALL single post pages, regardless of whether they are parent posts or child posts:

<?php if ( is_single() ) : ?>

<div class="col-1 art-singles art-controls">
   <?php next_post_link('%link', '←'); ?>  &nbsp;
   <a href="<?php get_home_url(); ?>/work" alt="all work">All</a>&nbsp;  
   <?php previous_post_link('%link', '→'); ?>
   <a href="#" alt="enlarge image" class="enlarge-it"><p style="text-transform: none;">Enlarge</p></a>
</div>

<?php endif; ?>

I’m stumped on how to make a distinction between single parent posts versus single child posts.

I already tried reworking it this way to show just on parent posts:

 <?php if($post->post_parent != 0) {

   echo "<?php next_post_link('%link', '←'); ?>";
   echo "&nbsp;"; 
   echo "<a href='";
   get_home_url();
   echo "/work' alt='all work'>All</a>";
   echo "&nbsp;";
   echo "<?php previous_post_link('%link', '→'); ?>";
  }
  ?>

This just caused the content to not display at all on parent or child single posts.

In short: Is there something I can add to the if statement to show the div only on parent single posts? And something I can add to show the div only on child single posts?

Read more here: PHP to display div only for parent posts

Leave a Reply

Your email address will not be published. Required fields are marked *