javascript - 将类添加到侧边栏中的事件分类链接

标签 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_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();
    }
}
}

看起来像这样

preview preview

我想要事件页面中的链接具有不同的颜色,例如红色, 我该怎么做...谢谢大家

最佳答案

没关系,我在这里有我自己的解决方案..,顺便说一句谢谢你的评论

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

关于javascript - 将类添加到侧边栏中的事件分类链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28011666/

相关文章:

javascript - 异步调用 firebase 后,Angular 应用程序未更新(脏检查)

javascript - 浏览器扩展(例如 “memonic”)如何将数据与特定用户相关联?

php - 当我使用加盐的 CRYPT_MD5 来加密我的密码时,加密的是什么?

php - 使用具有本地依赖项的 Composer

html - 将不透明度应用于背景图像而不是文本

javascript - 发送/接收图像以响应 http

Javascript - 数组上的 flatMap 方法 - (flatMap 不是函数)

php - Xampp Zend_Mail_Protocol_Exception:无法找到套接字传输“ssl”-library\Zend\Mail\Protocol\Abstract.php:277

html - 为什么 css 背景大小会旋转图像?

css - 如何制作动画404齿轮?