显示自定义邮政类型分类子类别及其公告

时间:2011-05-25 作者:Jon

如何为自定义帖子类型分类法执行此操作?

<?php
//get all child categories for category 15, then for each child category display the posts
$parent_cat = 15;
$taxonomy = \'category\';
$cat_children = get_term_children( $parent_cat, $taxonomy );

if ($cat_children) {
echo \'<p>Category 15</p>\';
foreach($cat_children as $category) {
$args=array(
  \'cat\' => $category,
  \'post_type\' => \'post\',
  \'post_status\' => \'publish\',
  \'posts_per_page\' => -1,
  \'caller_get_posts\'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
  echo \'List of Posts belonging to Category \' . $category;
  while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php     the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    <?php
  endwhile;
}
}
}
wp_reset_query();  // Restore global post data stomped by the_post().
?>

1 个回复
SO网友:Bainternet

你做得很好你只需要改变\'post_type\' => \'post\' 从post到自定义类型。

结束

相关推荐