我需要你的帮助。
我想从我的模板分类广告中找出最后一个(数字)。下面是代码:
<?php
$the_query = new WP_Query( array(
\'showposts\' => 10,
\'post_type\' => \'ad\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'ad_category\',
\'field\' => \'id\',
\'terms\' => array(\'8\')
)
)
));
if($the_query->have_posts()):
?>
<div class="feat-ad column col12"><!-- featured ad -->
<h3 class="widget-title">Category</h3>
<ul id="first-carousel" class="first-and-second-carousel">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<?php colabs_image(\'width=150&height=150&play=true\');?>
<a href="<?php the_permalink();?>"><?php the_title();?></a>
</li>
<?php endwhile; ?>
</ul>
</div><!-- end featured ad -->
<?php endif;?>
我尝试了showpost,但在一个广告中没有出现任何内容。。。这甚至不是最后一次宣布。
SO网友:thomascharbit
尝试以下操作:
$the_query = new WP_Query( array(
\'post_type\' => \'ad\',
\'posts_per_page\' => 10,
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'ad_category\',
\'field\' => \'id\',
\'terms\' => array(\'8\')
)
)
));
posts_per_page
说明要从DB中检索的项目数orderby
指示按日期排序项目(可选,因为这是默认值)order
设置为DESC
从最新到最旧的项目检索