Javascript 将类添加到侧栏中的活动分类链接

Javascript 将类添加到侧栏中的活动分类链接,javascript,php,css,wordpress,function,Javascript,Php,Css,Wordpress,Function,我想在侧边栏中的分类法活动链接中添加一个css类,我有以下代码 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_te

我想在侧边栏中的分类法活动链接中添加一个css类,我有以下代码

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();
    }
}
}
看起来像这样

我想在活动页面的链接与不同的颜色,如红色,
我该怎么做。。thx伙计们

没关系,我这里有我自己的解决方案..谢谢大家的评论

<?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(); } ?>

主动链接?看起来你不会有一个活跃的链接。你只是简单地吐出一个列表,没有任何东西表明哪一个是活动的。考虑使用此菜单。如果在活动页面广告类中添加到Li元素,我该怎么做呢?