【发布时间】:2016-08-05 08:26:24
【问题描述】:
我希望能够在浏览父类别时列出所有帖子(子和父)。
像这样:
- 家长(显示孩子 1 和孩子 2 的帖子)
- 孩子 1(仅显示孩子 1 的帖子)
- 孩子 2(仅显示孩子 2 的帖子)
使用下面的代码(放置在 category.php 中)当我在父类别中时,我没有得到所有的帖子。我只从一个子类别而不是几个子类别中获取帖子。
有什么办法解决这个问题吗?
<?php get_header(); ?>
<div class="container">
<div class="row">
<?php get_template_part( 'include-cat-tag' ); ?>
<div class="col-xs-12 col-sm-9 col-md-9 list-page-middle">
<header class="clearfix">
<h1><?php single_cat_title( '', true ); ?></h1>
</header>
<?php
wp_reset_query();
$categories = get_the_category();
$category_id = $categories[0]->cat_ID;
$args = array(
'posts_per_page' => 100,
'category__in' => array($category_id),
'orderby' => 'meta_value title',
'order' => 'ASC',
'post_status' => 'publish',
'meta_key' => 'betyg',
'child_of' => $category_id
);
query_posts( $args );
if (have_posts()): while (have_posts()) : the_post();
get_template_part( 'include-list-post' );
?>
<?php endwhile; ?>
<?php else: ?>
<?php get_template_part( 'include-no-post' ); ?>
<?php endif; ?>
</div>
</div>
<?php
get_template_part( 'include-list' );
get_template_part( 'include-social' );
?>
</div>
</div>
<?php get_footer(); ?>
【问题讨论】:
标签: wordpress