在wordpress中以ASC顺序显示最新的帖子

时间:2015-06-18 07:12:47

标签: php wordpress

我正在努力获得最新的帖子 在结果字符串中显示如

12th Jul 2015
24th Mar 2015
18th Jan 2015

我希望将其显示为

18th Jan 2015
24th Mar 2015
12th Jul 2015

我有查询字符串

<?php query_posts(array( 'cat' => '17', 'orderby' => 'post_date', 'order' => 'DESC', 'posts_per_page' => 3 ) ); ?>

提前致谢...

1 个答案:

答案 0 :(得分:0)

我认为这有效:

<?php
$myposts = get_posts('cat=3&showposts=3');
if ($myposts) {
$uc=array();
  foreach ($myposts as $mypost) {
    $uc[]=$mypost->ID;
    }
  }
    $args=array(
      'post__in' => $uc,
      'orderby' => 'post_date',
      'order' => 'ASC',
      'posts_per_page' => 3,
      'caller_get_posts' => 1
    );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'Category 3, lastest posts, sorted oldest to newest';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><small><?php the_time('m.d.y') ?> </small><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
       <?php
      endwhile;
    } //if ($my_query)
  wp_reset_query();  // Restore global post data stomped by the_post().
?>