$cat = get_query_var( \'cat\' );
$args = array(
\'post_status\' => \'publish\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'category\', //may be categories, I never remember, try both
\'field\' => \'slug\', //may need to use ID, depends on output
\'terms\' => $cat
//children are included by default
)
)
);
$posts = new WP_Query( $args );
这将为您提供一个post对象数组。您可以使用
setup_postdata()
如果你想的话,把它输入到一个循环中。当您添加子类别时,此代码将是可扩展的,它们也将被查询。
文档:WP_Query
, setup_postdata()
更新
<?php
$cat = get_query_var( \'cat\' );
$args = array(
\'post_status\' => \'publish\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'category\', //may be categories, I never remember, try both
\'field\' => \'id\', //may need to use slug, depends on output
\'terms\' => $cat
//children are included by default
)
)
);
$my_posts = new WP_Query( $args );
?>
<?php if ( $my_posts->have_posts()) : while ( $my_posts->have_posts() ) : $my_posts->the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entryCategory">
<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_post_thumbnail( \'thumbnail\', array( \'class\' => \'alignright\' ) ); ?></a>
</div>