Wordpress Bootstrap手风琴:一次打开一张卡

时间:2019-06-17 00:40:06

标签: php jquery wordpress bootstrap-4

我的Bootstrap手风琴正在为Wordpress网站遇到一些障碍。单击新的手风琴卡后,所有手风琴卡保持打开(展开)状态。我希望完成的任务是一次只允许打开一张卡,单击新卡将关闭当前打开的卡。

这是工作代码的片段。

PHP

<?php 
        $args = array(
            'post_type' => 'our_work',
            'posts_per_page' => -1,
            'orderby' => 'category',
            'order' => 'ASC',
            'hide_empty' => 0,
        );  
        $loop = new WP_Query( $args );
        $cat = '';//set a variable to catch category
        $first = 0;
        echo '<div id="accordion" class="col-sm-12 offset-xl-4 col-xl-8" role="tablist">';
        while ( $loop->have_posts() ) : $loop->the_post();
            $post_cat = '';
            foreach(( get_the_category() ) as $category) { 
                $post_cat = $category->cat_name . ' '; 
            }

            if($first == 0){
                $first = 1;
                $cat = $post_cat;

                echo '<div class="card work-card box-shadow">';
                echo'<div class="card-header" role="tablist" id="'.get_the_id().'">';
                echo'<h5 class="mb-0">';
                echo'<a class="accordion-toggle collapsed toggle" data-toggle="collapse" href="#collapse'.get_the_id().'" aria-expanded="false" aria-controls="collapseOne">'.$post_cat.'</a>';
                echo'</h5>';
                echo'</div>';

                //start collapse pannel
                echo'<div id="collapse'.get_the_id().'" style="transition: all 0.5s ease 0s;" class="collapse nomnom work-card-collapse" aria-labelledby="heading'.get_the_id().'">';
            }

            if($cat != $post_cat){
                $cat = $post_cat;
                echo'</div>';//close collapse
                echo'</div>';//close box shadow
                echo '<div class="card work-card box-shadow">';
                echo'<div class="card-header" role="tablist" id="'.get_the_id().'">';
                echo'<h5 class="mb-0">';
                echo'<a class="accordion-toggle toggle" data-toggle="collapse" href="#collapse'.get_the_id().'"aria-expanded="false" aria-controls="collapseOne">'.$post_cat.'</a>';
                echo'</h5>';
                echo'</div>';
                //start collapse pannel
                echo'<div id="collapse'.get_the_id().'" style="transition: all 0.5s ease 0s;" class="collapse nomnom"  aria-labelledby="heading'.get_the_id().'">';
            }
            echo'<div class="card-block in">';
            echo'<h3 class="underline">'.get_the_title().'</h3>';
            echo'<p>'.get_the_content().'</p>';
            echo'</div>';

            if (($loop->current_post +1) == ($loop->post_count)) { 
                echo '</div>';//close collapse 
                echo '</div>';//box shadow close
            } 
        endwhile; 
        wp_reset_query();
        echo '</div>';//close accordian close
    ?>

我看过与该主题相关的帖子,建议删除“数据父级” ,但我的代码未包含...

该怎么办?

0 个答案:

没有答案