2014-10-10 272 views
1

我使用此代码在一个类别下显示的子类别WordPress的帖子而已,没有

<?php $this_category = get_category($cat); 

    $id = get_query_var('cat'); 
    $args = array( 'parent' => $id); 
    $catdesc = $cat->category_description; 
    foreach (get_categories($args) as $cat) 
:?> 
<a href="<?php echo get_category_link($cat->term_id); ?>"> 
<?php echo ("$cat->cat_name"); ?></a> 

    <?php endforeach ?>  

    <?php while (have_posts()) : the_post(); ?> 

    <?php 
     get_template_part('content/content', get_post_format()); 
    ?> 

    <?php endwhile; ?> 

的问题,以显示子类别,在类别中显示的所有职位的类别和子类别下。

但我想只显示该子类下的帖子,而不是在类别中。

回答

0
Try this: 

$category = 'Jobs'; 

$categoryID = get_cat_ID($category); 

$subcategories = get_categories('child_of=' . $categoryID); 

foreach($subcategories as $subcategory) { 

    $subcategory_posts = get_posts('cat=' . $subcategory->cat_ID); 

    foreach($subcategory_posts as $subcategory_post) { 

      $postID = $subcat_post->ID; 

      echo get_the_title($postID); 
    } 
} 

For more details go to this https://wordpress.org/support/topic/how-to-list-posts-by-sub-category 
相关问题