Wordpress category sort by date

巧了我就是萌 提交于 2020-01-06 15:29:26

问题


I would like to sort my post in specyfic category ASC by date. My code is:

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

This code display 4 posts from category "3". How to sort this posts? I found:

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

but it doesn't work.

Regards.


回答1:


try this,,

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


来源:https://stackoverflow.com/questions/22689315/wordpress-category-sort-by-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!