Viewing 1 replies (of 1 total)
  • Thread Starter gemba

    (@gemba)

    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
    }
    }
    
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Highlight current page’ is closed to new replies.