Home › Forums › General Issues › Add "current" class to list of related posts › Reply To: Add "current" class to list of related posts
I’ve written some code for you to show how you would compare the current ID to the loop ID:
<?php foreach( $posts as $post): ?> <li class="lesson <?php if( get_the_ID() == $post->ID): ?>active<?php endif; ?>"> <h3><a href="<?php echo get_permalink( $post->ID ); ?>"><?php echo get_the_title( $post->ID ); ?></a></h3> </li> <?php endforeach; ?>
Please note I have removed the setup_postdata function as this will only cause you headaches if you are not careful with it
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.