我正在開發一個頁面,該頁面要求我在手風琴式下拉列表中顯示自定義帖子類型的類別列表。類別名稱將作為手風琴標題,內容將是與每個特定類別相關聯的帖子。下圖總結了我最終要完成的工作。我已經能夠成功檢索類別名稱并將它們分配給手風琴下拉列表,但發生的情況是我的代碼正在添加新單元格,即使這兩個帖子與類似的類別名稱相關聯。Arrrrrg,我覺得我很接近!這是到目前為止我的代碼的一個片段。<div id="accordion" class="col-8" role="tablist" aria-multiselectable="true"> <?php $args = array( 'post_type' => 'our_work', 'posts_per_page' => -1, 'orderby' => 'category', 'hide_empty' => 0, ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); ?> <div class="card box-shadow"> <div class="card-header" role="tab" id="<?php the_ID(); ?>"> <h5 class="mb-0"> <a data-toggle="collapse" data-parent="#accordion" href="#collapse<?php the_ID(); ?>" aria-expanded="false" aria-controls="collapseOne"> <?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?> </a> </h5> </div> <div id="collapse<?php the_ID(); ?>" style="transition: all 0.5s ease 0s;" class="collapse nomnom" role="tabpanel" aria-labelledby="heading<?php the_ID(); ?>"> <div class="card-block"> <h1><?php the_title(); ?></h1> <p><?php the_Content(); ?></p> </div> </div> </div> <?php endwhile; wp_reset_query(); ?> </div>我懷疑正在發生的是我沒有正確設置我的循環并因此添加了一個新單元格。我對使用“WordPress 循環”還很陌生,所以任何建議都將不勝感激?。?!
- 1 回答
- 0 關注
- 181 瀏覽
添加回答
舉報
0/150
提交
取消