我很难让它正常工作。我已经创建了一个名为article\\u subjects的自定义分类法,并正在循环,显示每个术语;但我正在努力为每学期获取最新帖子
<section>
<?php
$args = array (
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'hide_empty\' => true,
\'number\' => \'4\'
);
$terms = get_terms( \'article_subjects\', $args );
foreach ( $terms as $term ) { ?>
<div>
<?php
$postargs = array (
\'tax_query\' => array (
array (
\'taxonomy\' => \'article_subjects\',
\'field\' => \'name\',
\'terms\' => $term->slug,
\'number\' => \'1\'
)
)
);
global $wp_query;
$posts = new WP_Query($args);
foreach ( $posts as $post ) { ?>
<p class="date"><?php echo $post->the_date ?></p>
<h3><?php echo $post->the_title ?></h3>
<p class="description"><?php echo $post->the_excerpt ?></p>
<?php } ?>
</div>
<?php }
?>
</section>
SO网友:davidcondrey
以前把事情搞混了,现在就开始了。谢谢这是我最终使用的代码:
<section id="top-columns">
<?php $args = array (
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'hide_empty\' => true,
\'number\' => \'4\'
);
$terms = get_terms( \'article_subjects\', $args );
foreach ( $terms as $term ) {
$post_args = array (
\'post_type\' => \'post\',
\'article_subjects\' => $term->name,
\'posts_per_pge\' => \'1\'
);
$query = new WP_Query( $post_args );
while ( $query->have_posts() ) {
$query->the_post(); ?>
<div id="post-<?php the_ID(); ?>">
<?php
the_date();
the_title();
the_excerpt();
?>
</div>
<?php }
wp_reset_postdata();
} ?>
</section>