Background articles are sorted by modification time
Add the following php code to functions. php of the current topic:
The code is as follows: |
Copy code |
Function ludou_set_post_order_in_admin ($ wp_query ){ If (is_admin ()){ $ Wp_query-> set ('orderby', 'modified '); // Add the latest modified article to the beginning // If you want to post the latest modified article, change DESC to ASC. $ Wp_query-> set ('order', 'desc '); } } Add_filter ('pre _ get_posts ', 'ludou _ set_post_order_in_admin '); |
Actually, I am adding a function. This function is to add modified to the sorting field, and modified is the last update time in this wordpress blog.
Foreground articles are sorted by modification time
1. Open the current WordPress topic directory, Open index. php, and search for the code:
The code is as follows: |
Copy code |
<? Php While (have_posts (): the_post ();?> |
2. Insert the following lines of code before the while
The code is as follows: |
Copy code |
$ Paged = (get_query_var ('paged '))? Get_query_var ('paged'): 1; $ Args = array ( 'Orderby' => modified, 'Showposts' => 10, 'Paged' => $ paged ); Query_posts ($ args ); |
3. Continue searching
The code is as follows: |
Copy code |
<? Php endwhile;?>
|
4. Replace it
The code is as follows: |
Copy code |
<? Php endwhile; wp_reset_query () ;?> |
1. According to the orderby value, the document can be sorted in many ways. Below are several common values and their corresponding sorting methods:
Title: Press the title;
Date: based on the release date;
Modified: by the modification time;
ID: by document ID;
Rand: random sorting;
Comment_count: number of comments
2. If you want to modify the order of articles on the tabs, category pages, and other archive pages at the same time, you can also modify archive. php under the topic directory according to the method above.
Save, refresh, success!