wordpress show all custom taxonomies and their associate posts
Is their any way in wordpress custom taxonomy to show all ca开发者_开发知识库tegories and associate their posts as well means:
my category1
post 1
post 2
post 3
post 4
my category2
post 1
post 2
post 3
post 4
note i have to do this in custom post type, taxonomy.
this should work, I haven't tested it thorough
$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>';
}
source:
http://codex.wordpress.org/Function_Reference/get_categories
http://codex.wordpress.org/Template_Tags/get_posts
questions just ask
精彩评论