假設我有以下幾類。僅顯示來自一個子類別的文章 - Wordpress
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 – 2013-04-22 13:11:57
的人顯示你的代碼。 – Rikesh 2013-04-22 13:16:01
嗨Royal和Rikesh,我添加了一個示例代碼。目前我不知道如何顯示子類別的帖子。此代碼將顯示來自類別的所有帖子及其子類別。 – Anam 2013-04-22 13:31:01