【发布时间】:2013-04-22 13:09:12
【问题描述】:
假设我有以下类别。
Movies
----- Action
----- Science fiction
----- Drama
Music
----- POP
----- Rock
这里,电影和音乐是父类别,其余是子类别。
如果我只想显示音乐类别中的 POP 音乐(POP 帖子),我该怎么做。
请帮忙!
我不知道如何显示子类别的帖子。我唯一拥有的是一个示例代码,它可以显示父类别和子类别的帖子。
<?
// 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();
?>
【问题讨论】:
-
举个例子,对于不熟悉WordPress的人来说,一般如何显示结果
-
显示您尝试过的代码。
-
嗨 Royal 和 Rikesh,我添加了一个示例代码。目前我不知道如何显示子类别中的帖子。此代码将显示一个类别及其子类别中的所有帖子。