Skip to content

Instantly share code, notes, and snippets.

@secretstache
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save secretstache/51c2a9860c0e56a5684f to your computer and use it in GitHub Desktop.
Save secretstache/51c2a9860c0e56a5684f to your computer and use it in GitHub Desktop.
Dynamically add current-menu-item to list items
<?php $story_nav = new WP_Query( $args ); ?>
<?php if ( ! empty( $story_nav ) ) { ?>
<?php $queried_object = get_queried_object(); ?>
<?php $current_page_id = $queried_object->ID; ?>
<ul class="featured-stories">
<li>Featured Stories
<ul>
<?php while ( $story_nav->have_posts() ) { ?>
<?php $story_nav->the_post(); ?>
<?php $list_id = get_the_ID(); ?>
<li class="story<?php echo ( $current_page_id === $list_id ) ? ' current-menu-item': ''; ?>">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php } // endwhile $story_posts->have_posts() ?>
</ul>
</li>
<?php wp_reset_postdata(); ?>
</ul>
<?php } // endif ! empty( $story_nav ) ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment