WordPress - 只显示父类别的帖子不是子类别的帖子
问题描述:
我一直在努力从Wordpress中提取父类别的帖子。当我试图显示唯一的父类别发布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";
+0
谢谢。简单的改变让我的生活变得更轻松......再次感谢 – Anam 2013-04-22 11:30:03
你真的在你的问题不应该张贴outcommented代码。这样做,并修复你的代码缩进(我很高兴,但不知道什么时候很难说)。 – timss 2013-04-22 05:45:50
代码有什么问题?它会显示父类别和子类别的所有帖子..它对每个安装的单词按键都有效。 – Anam 2013-04-22 05:49:23
Outcommented代码和代码缩进,而不是你的代码实际上做什么。 – timss 2013-04-22 05:50:43