簡體   English   中英

奇怪的Wordpress類別帖子順序

[英]Weird Order of Wordpress Category Post

有人看過嗎?

當我們在此處訪問wordpress類別帖子之一時:

最重要的是,它不是最新發布的文章,而是最古老的文章。

在此處輸入圖片說明

php代碼的哪一部分應該更改? 此鏈接適用於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' );

如果您使用任何自定義查詢,請在循環后的'order'=>'DESC'中添加此查詢

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

    $q = new WP_Query($args);

或將其粘貼在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