Skip to content

Instantly share code, notes, and snippets.

@billerickson billerickson/functions.php Secret
Created Nov 15, 2018

Embed
What would you like to do?
<?php
$parents = array_reverse( get_ancestors( get_the_ID(), 'page' ) );
$parents[] = get_the_ID();
$loop = new WP_Query( array(
'post_type' => 'page',
'post_parent' => $parents[0],
'orderby' => 'menu_order',
'order' => 'ASC',
) );
if( $loop->have_posts() ):
echo '<ul>';
while( $loop->have_posts() ): $loop->the_post();
$class = 'menu-item';
if( get_the_ID() == get_queried_object_id() )
$class .= 'current-menu-item';
echo '<li class="' . $class . '"><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
endwhile;
echo '</ul>';
endif;
wp_reset_postdata();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.