admin管理员组文章数量:1310513
I want to loop through categories and display the post's title under each category dropdown. Clicking the post name from the dropdown will display the post content in a tab pane in WordPress. Can someone please suggest a code solution.
<?php
$args = array(
'taxonomy' => 'types',
'orderby' => 'name',
'order' => 'ASC'
);
$cats = get_categories($args);
$c = 1;
foreach($cats as $cat) {
?>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle <?=($c == 1) ? 'active' : ''?>" href="#<?php echo $cat->name; ?>" role="button" data-toggle="tab" aria-haspopup="true" aria-expanded="false"><?php echo $cat->name; ?></a>
<div class="dropdown-menu">
<?php
$cat_slug = $category->slug;
$the_query = new WP_Query(array(
'post_type' => 'project',
'category_name' => $cat_slug
));
while($the_query->have_posts()){
$the_query->the_post();
?>
<a class="dropdown-item" href="#<?php the_ID(); ?>" data-toggle="tab"><?php the_title(); ?></a>
<?php }
wp_reset_postdata();
?>
</div>
</li>
<?php
$c++;
}
wp_reset_postdata();
?>
本文标签: phpLoop through categories and display posts title under each dropdown
版权声明:本文标题:php - Loop through categories and display posts title under each dropdown 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741789337a2397568.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论