Have you ever tried to change the standard order of posts on the blog page of your site? By default, posts are sorted according to the date each post is published, and there is no built-in method to change the order in which posts are displayed. If you want to change the post order, there are three options: Change the release date of the article, write code that sorts the article using parameters instead of the release date, or find the plug-in to perform the action. Changing the publishing date is not an option that many blogs can perform. Therefore, this article introduces the second and third options in the list. First, we will show you how to create a custom plug-in to enable custom post ordering. Second, let’s look at two plug-ins that can be used in the word press plug-in directory to create custom mail orders. The
Antecedents this post assumes a specific level of word press programming knowledge. If you have never created a simple plug-in or page template before, it is difficult to imitate. If it is difficult to imitate, the following posts will help you learn what you need to understand the materials in this tutorial. How to create a custom page template WordPress plug-in in WordPress wpuquery deep guide to conquest if you are not interested in building a custom plug-in, you can jump to the list of available plug-ins in the WordPress plug-in directory to make the process much easier. The
We also import all the code in this tutorial into the GitHub repository. If you want to see what the finished product looks like, you can view and all the code in GitHub. Building your own custom post order plug-in to implement custom mail orders requires two main steps. Add a custom field to the post that can be used as the basis for sorting the post. Modify the default word press loop or build a custom loop and add it to the sidebar component or custom page template to achieve a custom sort order. We’ll add custom fields to the edit WordPress post screen and get started. But before that, you must start the WordPress development environment, create a new plug-in folder, and create plug-in files in that folder. If you want to view the structure of my plug-in, you can view the finished products in GitHub. The
On the \
The callback function of the above code is \
Finally, user input must be saved in the database. Simply add the following code to the plug-in: Load summary 7687e962c9aced9d8f4cf2520731d711 this code
First, make sure that nonce is set and that the user has permission to change the post. If everything is confirmed, the post metadata will be updated to the new custom post subscription value. In the last section of \
To view the current article sort order values in the current state, you must open each article and view the custom meta box that you just added to the edit article screen. Not very convenient. To quickly view the current post order value assigned to each post, let’s add a custom sort order value to the administrator post list. First, you must add a custom column to the list of posts in the administrative area. Simply add the following code to the plug-in: After loading the summary 6fe100e61b88e608bb9bd72270f6698c, you must obtain a customized post subscription value for each post and list it in a new column. This is not difficult, just add this function to the plug-in file. The
The load summary 74a8f978d11efb0c12c6e43cf7f820f3 is amazing. Now, you can easily view Posts assigned custom sort order values by accessing the administrator’s blog post list. When viewing the list of blog posts in the management area, the situation is as follows: Make good use of customized email orders so that you can assign custom order to posts. Now it’s time to make good use of custom order. But before doing so, \
Customize the sorting of all posts and display the customized sorting list on the blog post page. In a busy blog, you may not want to do this, but if you use WordPress to host a series of educational posts and do not often add new posts, this may be a useful way to sort posts in any order. Use a custom page template to create a list of selected posts and display them in the selected order. For example, you can select a list that contains only posts that belong to a specific category, and then sort them in the desired order. Starting with a few custom sorted posts, create a list of blog posts that contains all the remaining posts in standard order. Really, the sky is the limit. This is a viable idea if you can consider the use of a custom sort order and understand how to implement the idea. Let’s take a quick look at the three ideas above and see how they are implemented. The
Replace posts on the blog page with a custom sort list the easiest way to use a custom sort order is to replace the standard post list on the website blog page with a custom sorted post directory. To do this, you only need to add the following features to the plug-in: Load summary 02c05a487aa0b302bff101d43d9e533f this function only displays the posts assigned custom sort order values. Posts that do not specify a custom sort order value will not be displayed on the blog page. That is, you must specify a custom sort order value for all posts to be displayed. The
Filter list of customized sorting posts to create a filter list of customized sorting posts, you must use the wp\u query class. What you need to do is create a query that contains the parameters used to filter the list, and then add a custom sort order to the query. You can see: Load summary 9fd1ede18ae87ac217580a71bc0a290d the query is first in the category with ID 94
To display the final posts in a specific order, you can select several different options. The most flexible option is to build your own plug-in and then manually implement custom sorting. However, if you cannot develop a custom solution, you can use the easy-to-use plug-ins in the word press directory to do your work. Have custom mail orders been implemented? So, what is your goal and how did you achieve it? Please tell me in the comments section! Tag: development post WP query