If permalink is equal to current site url

Using large sliding banners with linked content can be both a blessing and a curse.  This adds a beautiful level of style and information to the site, but also takes up a lot of space, and provides a lot of repetitive information that can be difficult for new visitors to navigate.

To help visitors navigate with ease, you can target links that repeat throughout your website, and remove them from the transitions / hide those slides entirely on the equivalent urls.

Used within the loop:

$current_id = $post->ID;
<?php $current_class = ( $current_id == $post->ID ) ? 'class="current_banner"' : ''; ?>
<a <?php if ( $current_class ) echo $current_class; ?> href="<?php the_permalink(); ?>">Learn More &gt;</a>

Complete example using a for loop:

foreach($sliders as $post) : setup_postdata($post);
$current_id = $post->ID;
?>
	    
<div class="banners">
     <?php the_post_thumbnail(); ?>
     <div class="banner_content">
          <h1><?php the_title(); ?></h1>
          <?php the_content();?>
          <?php $current_class = ( $current_id == $post->ID ) ? 'class="current_banner"' : ''; ?>
          <a <?php if ( $current_class ) echo $current_class; ?> href="<?php the_permalink(); ?>">Learn More &gt;</a>
     </div>
</div>

<?php endforeach; wp_reset_postdata(); ?>

 

 

Sited here and here

Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.