Dynamic highlight not working
-
Hi folks,
I’m trying to highlight the current post in a dynamic menu but WordPress is beating me on this.
The problem is the menu is totally dynamic. Items can be added to it. So the WordPress default solution doesn’t work. I used the solution proposed in this post, but it’s not working: https://www.ads-software.com/support/topic/highlighting-current-post-title-in-get_posts-list?replies=8#post-1130031
Here’s my code. What’s wrong?
<ul id="2"> <?php $IDOutsideLoop = $post->ID; global $post; $args = array( 'numberposts' => 500, 'category' => 3 ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); ?> <li<?php if($IDOutsideLoop == $post->ID) { echo " class=\"current\""; } ?>> <a href="<?php the_permalink(); ?>" > <?php the_title(); ?> </a> </li> <?php endforeach; ?> </ul>
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Dynamic highlight not working’ is closed to new replies.