他们以任何方式使用wordpress自定义分类法来显示所有类别并将其帖子关联起来意味着:
my category1
post 1
post 2
post 3
post 4
my category2
post 1
post 2
post 3
post 4
请注意我必须在自定义帖子类型,分类中执行此操作。
答案 0 :(得分:4)
这应该有效,我还没有彻底测试过
$args = array (
'type' => 'post', //your custom post type
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0 //shows empty categories
);
$categories = get_categories( $args );
foreach ($categories as $category) {
echo $category->name;
$post_by_cat = get_posts(array('cat' => $category->term_id));
echo '<ul>';
foreach( $post_by_cat as $post ) {
setup_postdata($post);
echo '<li><a href="'.the_permalink().'">'.the_title().'</a></li>';
}
echo '</ul>';
}
源:
http://codex.wordpress.org/Function_Reference/get_categories
http://codex.wordpress.org/Template_Tags/get_posts
问题只是问