简体   繁体   English

奇怪的Wordpress类别帖子顺序

[英]Weird Order of Wordpress Category Post

Does anyone have ever seen this? 有人看过吗?

When we're accessing one of wordpress category post here: 当我们在此处访问wordpress类别帖子之一时:

On the top item, it's not the latest posted article instead it's the oldest one. 最重要的是,它不是最新发布的文章,而是最古老的文章。

在此处输入图片说明

Which part of the php code should be changed ? php代码的哪一部分应该更改? It's for wordpress version of 4.5 from this link. 此链接适用于Wordpress 4.5版本

 function change_category_order( $query ) {
 $category = get_queried_object(); 
  $cat_id=$category->term_id;
  if ( $query->is_category($cat_id) && $query->is_main_query() ) { 
  $query->set( 'order', 'DESC' ); 
  } 
  } 
 add_action( 'pre_get_posts', 'change_category_order' );

If you use any custom query add this also in post loop 'order' => 'DESC' 如果您使用任何自定义查询,请在循环后的'order'=>'DESC'中添加此查询

     $args = array(
    'post_type' => 'post',
    'order' => 'DESC',  );

    $q = new WP_Query($args);

or paste this in function.php 或将其粘贴在function.php中

   add_action( 'pre_get_posts', 'my_change_sort_order'); 
     function my_change_sort_order($query){
     if(is_archive()):
     //If you wanted it for the archive of a custom post type use:          is_post_type_archive( $post_type )
       //Set the order ASC or DESC
       $query->set( 'order', 'DESC' );
       //Set the orderby
       //$query->set( 'orderby', 'title' );
    endif;    
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM