Wordpress类别按日期排序

时间:2014-03-27 13:36:08

标签: php wordpress sorting themes categories

我想按日期在特定类别ASC中对我的帖子进行排序。 我的代码是:

<?php $cat_id = 3; //the certain category ID
$latest_cat_post = new WP_Query( array('posts_per_page' => 4, 'category__in' => array($cat_id)));
if( $latest_cat_post->have_posts() ) : while( $latest_cat_post->have_posts() ) : $latest_cat_post->the_post();  ?>
<?php the_post_thumbnail('thumbnail', array('class' => 'thumbnailmini')); ?>
<h3><?php the_title(); ?></h3>  
<?php the_content('więcej ->'); ?>
<div class="clear"></div>
<?php endwhile; endif; ?>

此代码显示4个类别&#34; 3&#34;的帖子。如何排序这篇文章? 我找到了:

<?php query_posts ('cat=3&orderby=date&order=ASC'); ?>

但它没有用。

问候。

1 个答案:

答案 0 :(得分:0)

试试这个,

<?php $cat_id = 3; //the certain category ID
$latest_cat_post = new WP_Query( array('posts_per_page' => 4,'orderby' => 'date','order' => 'ASC', 'category__in' => array($cat_id)));
if( $latest_cat_post->have_posts() ) : while( $latest_cat_post->have_posts() ) : $latest_cat_post->the_post();  ?>
<?php the_post_thumbnail('thumbnail', array('class' => 'thumbnailmini')); ?>
<h3><?php the_title(); ?></h3>
<?php the_content('wiecej ->'); ?>
<div class="clear"></div>
<?php endwhile; endif; ?>