Conversation
supportI have related links listed on the left had side of my website which include links to the page you are currently on. I am trying to add a class to the link of the page you are currently on so that I can change the styling. Does anybody know how to do this? https://wordpress.org/plugins/related-links/
I have found the below code in the plugin which I want to change to be something like, if on the current page add a ‘active’ class but all other links on this page not show this class. if ( !function_exists( 'related_links' ) ) { function related_links() { $related_links = get_related_links(); ?> <?php if ( !empty( $related_links ) ) : ?> <ul class="related-links-list"> <?php foreach ( $related_links as $link ): ?> <li><a href="<?php echo $link['url']; ?>"><?php echo $link['title']; ?></a></li> <?php endforeach; ?> </ul> <?php endif; ?> <?php } } ?> I have amended the code to the below, but it shows a class for all links, can anyone help in only showing the class for the link of the page I am currently on if ( !function_exists( 'related_links' ) ) { function related_links() { $related_links = get_related_links(); ?> <?php if ( !empty( $related_links ) ) : ?> <ul class="related-links-list"> <?php foreach ( $related_links as $link ): ?> <li><a href="<?php echo $link['url']; ?>" class="<?php if (is_page( basename(get_permalink()) )) echo 'active'; ?>" ><?php echo $link['title']; ?></a></li> <?php endforeach; ?> </ul> <?php endif; ?> <?php } } ?>
I have found the below code in the plugin which I want to change to be something like, if on the current page add a ‘active’ class but all other links on this page not show this class. if ( !function_exists( 'related_links' ) ) { function related_links() { $related_links = get_related_links(); ?> <?php if ( !empty( $related_links ) ) : ?> <ul class="related-links-list"> <?php foreach ( $related_links as $link ): ?> <li><a href="<?php echo $link['url']; ?>"><?php echo $link['title']; ?></a></li> <?php endforeach; ?> </ul> <?php endif; ?> <?php } } ?> I have amended the code to the below, but it shows a class for all links, can anyone help in only showing the class for the link of the page I am currently on if ( !function_exists( 'related_links' ) ) { function related_links() { $related_links = get_related_links(); ?> <?php if ( !empty( $related_links ) ) : ?> <ul class="related-links-list"> <?php foreach ( $related_links as $link ): ?> <li><a href="<?php echo $link['url']; ?>" class="<?php if (is_page( basename(get_permalink()) )) echo 'active'; ?>" ><?php echo $link['title']; ?></a></li> <?php endforeach; ?> </ul> <?php endif; ?> <?php } } ?>