WordPress Hook – 改變文章列表排序(pre_get_posts)
一般在使用者瀏覽您部落格文章時
分類底下的文章順序是很重要的
通常WordPress預設會利用文章發布時間(post_date)做順序反序列出
這時候你會想修改你自己的排列方式
前提:
您必須要讓文章支援頁面功能(add_post_type_support),預設頁面才會有自訂排序(menu_order)
詳情請參考 Function_Reference/add_post_type_support
使用:
1 2 3 4 5 6 7 | function posts_order($query){ if( !empty($query) && $query->is_category ){ $query->set( 'order', 'ASC'); $query->set( 'orderby', 'menu_order' ); } } add_action('pre_get_posts', 'posts_order'); |
臉書留言
一般留言