将 class 添加到边栏中的活动分类 link

Adding class to active taxonomy link in sidebar

我想在我的侧边栏中添加一个 css class 到活动分类 link,我有这个代码..

function list_posts_by_taxonomy( $post_type, $taxonomy, $get_terms_args = array(), $wp_query_args = array() ){
$tax_terms = get_terms( $taxonomy, $get_terms_args );
if( $tax_terms ){
    foreach( $tax_terms  as $tax_term ){
        $query_args = array(
            'post_type' => $post_type,
            "$taxonomy" => $tax_term->slug,
            'post_status' => 'publish',
            'posts_per_page' => -1,
            'ignore_sticky_posts' => true
        );
        $query_args = wp_parse_args( $wp_query_args, $query_args );

        $my_query = new WP_Query( $query_args );
        if( $my_query->have_posts() ) { ?>
<div id="panel-project">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
  <div class="panel">
<div class="panel-heading" role="tab" id="heading<?php echo $tax_term->slug; ?>">
  <h4 class="panel-title">
    <a data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo $tax_term->slug; ?>" aria-expanded="true" aria-controls="collapse<?php echo $tax_term->slug; ?>">
      <?php echo $tax_term->name; ?>
    </a>
  </h4>
</div>
<div id="collapse<?php echo $tax_term->slug; ?>" class="panel-collapse collapse<?php if ( is_singular('csis_project') ) { ?> in<?php } ?>" role="tabpanel" aria-labelledby="heading<?php echo $tax_term->slug; ?>">
  <div class="panel-body">
    <ul>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
    </ul>
   </div>
  </div>
</div>
</div>
</div>
<?php } wp_reset_query();
    }
}
}

看起来像这样

我希望活动页面中的 link 具有不同的颜色,例如红色, 我该怎么做..谢谢大家

没关系,我在这里有自己的解决方案..,谢谢你的评论 btw

<?php $IDOutsideLoop = $wp_query->post->ID; global $post; ?>
<?php 
$taxonomyname = 'csis_project_category';
$taxonomyterms = get_terms($taxonomyname, 'hide_empty=0&hierarchical=0&order=DESC');
foreach ($taxonomyterms as $taxonomyterm) {
$args=array(
'post_type' => 'csis_project',
$taxonomyname => $taxonomyterm->name,
'post_status' => 'publish',
'order' => 'DESC',
'posts_per_page' => -1,
'caller_get_posts'=> 1,
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) { ?>
<div id="panel-project">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel">
<div class="panel-heading" role="tab" id="heading<?php echo $taxonomyterm->slug; ?>">
  <h4 class="panel-title">
    <a data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo $taxonomyterm->slug; ?>" aria-expanded="true" aria-controls="collapse<?php echo $taxonomyterm->slug; ?>">
      <?php echo $taxonomyterm->name; ?>
    </a>
  </h4>
</div>
<div id="collapse<?php echo $taxonomyterm->slug; ?>" class="panel-collapse collapse<?php if ( is_singular('csis_project') ) { ?> in<?php } ?>" role="tabpanel" aria-labelledby="heading<?php echo $taxonomyterm->slug; ?>">
  <div class="panel-body">
    <ul>
  <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <li <?php if(is_singular( 'csis_project' ) && $IDOutsideLoop == $post->ID) { echo " class='current'"; } ?>><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
  <?php endwhile; ?>
    </ul>
  </div>
</div>
</div>
</div>
</div>
<?php } wp_reset_postdata(); } ?>