我在这里硬编码的类别id,所以我可以拉在需要的类别和他们的职位类别。但理想情况下,我希望通过调用父类别来列出子类别和帖子来实现这一点。我的代码可以工作,但我不想这样做,我希望听到任何改进建议。我自己也在努力解决这个问题。
父类别为“winners-2018”。
<?php
$catz = array(6012,6013,6014,6015,6016);
foreach($catz as $i=>$categ){
$cat_archive = get_category ($categ);
//var_dump($cat_archive);
global $wp_query;
$args = array_merge( $wp_query->query_vars,array(
\'paged\'=>$paged,
\'posts_per_page\'=>10,
\'post_type\' => \'winners\',
\'category_name\' => $cat_archive->slug,
));
?>
<div class="outer">
<div class="inner">
<div class="inside">
<h1><?php echo $cat_archive->name; ?></h1>
</div>
<div class="left-content winners_fullwidth <?php if(is_category()) { echo $cat_archive->slug;} ?>">
<div class="wrap-content clearfix">
<?php
$cposts = get_posts(array(
\'category\'=>$categ,
\'orderby\' => \'title\',
\'order\' => \'ASC\',
\'posts_per_page\'=>10,
\'post_type\' => \'winners\',
));
foreach ( $cposts as $post ) : setup_postdata( $post ); ?>
<div class="press-box">
<?php if ( has_post_thumbnail() ) { ?>
<div class="art-image">
<a href="<?php echo get_permalink(); ?>" title="<?php the_title();?>"><?php the_post_thumbnail( \'square-blog\' ); ?></a>
</div>
<?php } ?>
<div class="art-right">
<h2><a class="perma" href="<?php echo get_permalink(); ?>"><?php the_title();?></a></h2>
<?php the_excerpt();?>
</div>
</div>
<?php endforeach;?>
<?php wp_reset_query(); ?>
</div><!-- wrap-content -->
</div><!-- left-content -->
</div>
<?php } ?>