我在主页上有一个部分,每当我写一篇新的“公文包”文章时,不管我把它们分配到哪个类别,都会显示一篇新的“公文包”文章。我要做的是使主页只显示one 特定类别(events
) 从这些投资组合帖子。我只是想知道我需要在下面的代码中更改什么才能做到这一点?
$args_for_latest = array(
\'numberposts\' => 5,
\'offset\' => 0,
\'orderby\' => \'port_date\',
\'order\' => \'DESC\',
\'post_type\' => \'port\',
\'tax_query\' => array(
\'taxonomy\' => \'portcat\',
\'field\' => \'slug\'
),
\'post_status\' => \'publish\'
);
$temp_latest = $wp_query;
$wp_query_latest= null;
$wp_query_latest = new WP_Query();
$wp_query_latest->query($args_for_latest);
while ($wp_query_latest->have_posts()) : $wp_query_latest->the_post();
$featured_image_latest = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'single-post-thumbnail\' );
$terms = get_the_terms($post->ID, \'portcat\');
$array_keys = array_keys($terms);
?>
<li><center><?php if ($featured_image_latest[0]!=="") {
echo "<img src=\'".TIMTHUMBURL."?w=120&h=120&src=".$featured_image_latest[0]."\' alt=\'".get_the_title()."\'>";
} else { ?>
<img src="<?php echo IMGURL; ?>/pic_article1.jpg" alt="" />
<?php } ?>
<span><?php echo $terms[$array_keys[0]]->name; ?></span>
<h4><?php the_title(); ?></h4>
<?php echo substr(get_the_excerpt(), 0, 70)."..."; ?></center>
<a href="<?php echo get_permalink($post->ID); ?>" class="read">Read more</a>
</li>
<?php endwhile; wp_reset_query(); ?>
SO网友:decoder88
也许这会有帮助。
$args_for_latest = array(
\'numberposts\' => 5,
\'category_name\' => \'events\', ///Use category slug,not name.
\'offset\' => 0,
\'orderby\' => \'port_date\',
\'order\' => \'DESC\',
\'post_type\' => \'port\',
\'tax_query\' => array(
\'taxonomy\' => \'portcat\',
\'field\' => \'slug\'
),
\'post_status\' => \'publish\'
);