添加一个wordpress活动类(add a wordpress active class)

我需要在<li>上放一个活动的类,所以当你在team_category中它会显示<li class="active">

<?php $sport = get_terms( 'team_category' ); if($sport){ ?><ul><?php foreach($sport as $s){ ?> <li><a href="<?php echo get_term_link( $s->slug, 'team_category' ) ?>"><?php echo $s->name; ?></a></li> <?php } ?></ul><?php } ?>

i need to put an active class on the <li> so the that when you are in a team_category it would display <li class="active">

<?php $sport = get_terms( 'team_category' ); if($sport){ ?><ul><?php foreach($sport as $s){ ?> <li><a href="<?php echo get_term_link( $s->slug, 'team_category' ) ?>"><?php echo $s->name; ?></a></li> <?php } ?></ul><?php } ?>

最满意答案

这样的事情应该有效。

<?php $sport = get_terms( 'team_category' ); ?> <?php if($sport): ?> <ul> <?php foreach($sport as $s): ?> <li class="<?php if($current_team == $s): ?>active<?php endif; ?>"> <a href="<?php echo get_term_link( $s->slug, 'team_category' ) ?>"><?php echo $s->name; ?></a> </li> <?php endforeach; ?> </ul> <?php endif; ?>

Something like this should work.

<?php $sport = get_terms( 'team_category' ); ?> <?php if($sport): ?> <ul> <?php foreach($sport as $s): ?> <li class="<?php if($current_team == $s): ?>active<?php endif; ?>"> <a href="<?php echo get_term_link( $s->slug, 'team_category' ) ?>"><?php echo $s->name; ?></a> </li> <?php endforeach; ?> </ul> <?php endif; ?>

更多推荐