簡體   English   中英

WordPress-僅顯示父類別帖子,不顯示子類別帖子

[英]WordPress - Display only Parent Category posts not sub categories posts

我一直在努力從Wordpress中提取父類別的帖子。 當我嘗試顯示唯一的父類別帖子時,wordpress查詢也會顯示子類別帖子。

如何省略子類別的帖子。 請幫忙!!..

<?
// Get the post ID
        $id = get_the_ID();         


        //get all the categories ( this function will return all categories for a post in an array)
        $category= get_the_category( $id );

        if ($category->category_parent == 0) {

        //extract the first category from the array
        $catID = $category[0]->cat_ID;

        //Assign the category ID into the query
        $verticalNavigationSwitcher = "cat=$catID&orderby=ID&order=ASC";
     }              


        $result = new WP_Query($verticalNavigationSwitcher);


                    //$featuredPosts->query('showposts=5&cat=3');
                    while ($result->have_posts()) : $result->the_post(); 
        ?>


   <li><a href='<?php the_permalink() ?>'><span><?php the_title(); ?></span></a></li>


  <?php 
            endwhile; 
            wp_reset_postdata();
 ?> 

嘗試使用以下查詢:

$verticalNavigationSwitcher = "category__in=$catID&orderby=ID&order=ASC";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM