1

我一直在努力从 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();
 ?> 
4

1 回答 1

0

尝试使用此查询:

$verticalNavigationSwitcher = "category__in=$catID&orderby=ID&order=ASC";
于 2013-04-22T07:07:06.403 回答