我正在使用以下内容,但我的帖子仍然按时间顺序排列(从最旧到新)。我的目标是在顶部发布最新帖子。(从最新到旧)
$catquery = new WP_Query( array (
'cat'=>'27',
'post_type'=>'news',
'orderby' => "post_date",
'order' => "DESC" )
);
while($catquery->have_posts()) : $catquery->the_post();
<p class="date"> <?php the_date(); ?> </p>
<h3><?php the_title(); ?></h3>
<p> <?php the_content('Read More', FALSE); ?>
我也尝试过orderby' => "date"
但没有运气。如何解决这个问题?
你的代码很接近,但有一些问题。
-
'cat'
需要 int 而不是字符串,所以你需要'cat'=>27,
- 而不是
post_date
你需要date
- 我不确定您需要哪个订单,因此请尝试
ASC
如果DESC
不起作用。
下面是新查询:
$catquery = new WP_Query(array (
'cat' => 27,
'post_type' => 'news',
'orderby' => 'date',
'order' => 'DESC'
));
- order(字符串) - 指定"orderby"参数的升序或降序。默认为"DESC"。
- "ASC" - 从最低值到最大值的升序(1,2,3;a,b,c)。
- "DESC" - 从最高值到最低值的降序排列(3, 2, 1; c, b, a)。
以下是参考资料: WP_Query
your post is custom post type so use this argument:'
<?php
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'news_category',
'field' => 'id',
'terms' => '27'
)
),
'post_type'=>'news',
'order_by'=>'date',
'order'=>'DESC',
'posts_per_page'=>-1
);
query_posts($args);
while ( have_posts() ) : the_post();
?>
<li>
<p class="date"><?php echo get_the_date('F j, Y'); ?></p>
<a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php
endwhile;
wp_reset_query();
?>