Target and add class to element in if statement based on slug
-
I’m creating a custom post type called events. I have created a taxonomy for event type with two categories, webinars and live-events. I’m trying to create a loop that will list these posts and apply a class to a span inside each list item if it is in the “webinars” category. I figured I could do this by targeting it’s slug. I’m a bit stuck on how to write this, but I feel I must be close. Here’s my attempt. Any help would be much appreciated.
<ul class=”eventlist”>
<?php $args = array( ‘post_type’ => ‘event’, ‘posts_per_page’ => 3 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?><li class=”event”>
<?php if ($tag->slug == ‘webinar’){ ?>
<span class=”fevdate web”>
<?php }
else { ?>
<div class=”fevdate”>
<?php } ?><?php the_title(); ?></span><!–/fevdate–>
<?php endwhile; ?>
- The topic ‘Target and add class to element in if statement based on slug’ is closed to new replies.