Support » Fixing WordPress » Get first child in WP_Query loop

  • Do you know a better way to do this?

    <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <?php $current_class = ( $current_id == $post->ID ) ? ' class="active"' : ''; ?>
    
    <?php
    	$childs = get_children(array(
    		'post_parent' => $post->ID,
    		'order' => 'ASC'
    	));
    	$child = reset($childs);
    ?>
    
    <li<?php if ( $current_class ) echo $current_class; ?>><a href="<?php echo get_permalink($child->ID); ?>"><?php echo get_the_title(); ?></a></li>
    <?php endwhile; endif; ?>
  • The topic ‘Get first child in WP_Query loop’ is closed to new replies.