我知道我可以用wp_list_categories()
列出类别,但我如何才能同时列出各个类别下的帖子,下面是我想要实现的示例:
类别1——cat1下的职位——cat1下的职位——cat2下的职位
我知道我可以用wp_list_categories()
列出类别,但我如何才能同时列出各个类别下的帖子,下面是我想要实现的示例:
类别1——cat1下的职位——cat1下的职位——cat2下的职位
最后,我这样解决了这个问题:
$hg_categories = get_categories();
foreach($hg_categories as $hg_category) {
echo \'<h3>\' . $hg_category -> name . \'</h3>\';
$hg_posts = get_posts(array(\'numberposts\' => -1, \'category\' => $hg_category -> cat_ID));
foreach ($hg_posts as $hg_post) {
if ($hg_post -> ID == get_the_ID()) {
echo \'<li class = "current-post"><a href = "\';
} else {
echo \'<li><a href = "\';
}
echo get_permalink ($hg_post -> ID);
echo \'">\';
echo $hg_post -> post_title;
echo \'</a></li>\';
}
}
如果有更好的解决方案,请告诉我,谢谢。
我刚切换到Wordpress,我想删除(或隐藏)主页上出现的“类别”部分。有可能吗?非常感谢。