簡體   English   中英

WordPress類別按日期排序

[英]Wordpress category sort by date

我想按日期對我在特殊類別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; ?>

該代碼顯示類別“ 3”中的4個帖子。 該帖子如何排序? 我發現:

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

但這不起作用。

問候。

嘗試這個,,

<?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; ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM