WordPress plug-in Building Part 3: setting up custom content types

In the second part of the series, we started a structured start by using the word press plug-in commercial tools to build a reasonable cache around future code. With this approach, we can start working with a number of free plug-in best practices. Now, let’s take a look at how to use the custom post type to provide part of the future custom creative content on the back end. This gives you the opportunity to actually use the WordPress plug-in commercial tool itself, import the test content into the system and play it with it. The
However, before you roll up your sleeves and start creating custom content types, we will eliminate the potential confusion of terms. Regardless of the level of word press experience before customizing several backgrounds of the post type, you are almost certainly exposed to the concept of the post somewhere. In most cases, you will quickly understand the basic differences between posts and pages, and move on to your daily life. But if we go deeper, there will be potential chaos in the background. Since the introduction of custom post types in 2010, Justin Tadlock pointed out in a wonderful introduction article on this topic that the word \
WordPress posts are actually a generic term for various content types. The software is provided with 5 types of articles and can be used directly on the gateway. The actual content of all the content in the page attachment revision menu of a post (which you may be used to think of as a blog post) is stored in the posts table of the database. This helps explain the large amount of mysterious data that is usually there when you first see it. User defined post types are the core of popular plug-ins such as woocomerce. You can also choose to create a custom post type. This provides an excellent, concise way to separate basic content from developers, and provides a simple, intuitive way for potential users to enter content on the back end. This is an approach that focuses on the core of many popular plug-ins and the platform itself. The
Let’s see how to set up one of these bad guys. As is the case with most plug-ins that are ready to register their own custom post type, it is best to always refer to the official plug-in manual when performing the first step. In this case, please go to the \
In our special case, the name of the plug-in is my RDM quotes, which is \/plugins\/my RDM quotes\/includes\/class my RDM quotes. Provide a full local path to PHP. After the file is opened, the define admin hooks () method
You can see that it is waiting to be used. In fact, when registering custom content types, we now have a general idea of where to jump in, but when we try something for the first time, it is always worth sitting on other people’s shoulders. Chris Wilcoxson’s recent presentation on common tools for using WordPress plug-ins is an interesting and useful lecture in itself, with convenient and complete documented working code that can be browsed on GitHub. The
From the main class file, we can see that the register_post\u type() function is being inserted into our speculation. Although it takes us to the admin folder and register\u post\u type() in turn through the custom function: male, it is actually the default admin class for the glory implementation of all arguments. Use a similar method in the local file \/include\/class-my-rdm-quotes. Start the operation from PHP. Private functiondefine\u admin\u hooks(){
$plugin\u admin= new my\u rdm\u quotes\u admin ($this->get\u plugin\u name(), $this->get\u version();
$this->loader->add\u action (‘admin\enqueue\u scripts’, $plugin\u admin,’enqueue\u Styles’);
$this->loader->add\u action (‘admin\enqueue\u scripts’, $plugin\u admin,’enqueue\u scripts’);
$this->loader->add\u action (\
}This simply instructs word press to find a custom function named new\u cpt\u rdm\u quote() in the relevant section of the admin folder. Then actually set the function to \/admin\/class-my-rdm-quote-admin. Add to PHP. In the following example, a slightly different version from Chris Wilcoxson’s original code is used. The
Male\/**
*Create a new custom post type
*The
*Starting with 1.0.0
*@Public access
*Use @register\u post\u type()
*\/The
Expose static functions new\u cpt\u rdm\u quote(){
$cap_type= \
$plural= \
$single= \
$cpt_name= \
$opts[\
$opts[‘capability\u type’] = $cap\u type;
$opts[\
$opts[‘exclude\u from\u search’] = false;
$opts[‘has_archive’] = false;
$opts[\
$opts[\
$opts[\
$opts[\
$opts[\
$opts[\
$opts[\
$opts[‘register\u meta\u box\u cb’] = ”;
$opts[\
$opts[\
$opts[\
$opts[\
$opts[‘labels’][‘add\u new’]=esc\u html\ (\
$opts[‘labels’][‘add\u new\u item’]=esc\u html\ (\
$opts[\
$opts[‘labels’][‘edit_item’] = e
Sc_html_ (\
$opts[\
$opts[\
$opts[\
$opts[‘labels’][‘new\u item’]=esc\u html\u (\
$opts[‘labels’][‘not_found’]=esc\u html\u (\
$opts[‘labels’][‘not_found_in_button’]=esc\u html\u (\
$opts[‘labels’][‘parent\u item\u colon’]=esc\u html\u (\
$opts[‘labels’][‘search_items’]=esc\u html\u (\
$opts[\
$opts[‘labels’][‘view_item’]=esc\u html\u (view \
Register\u post\u type (strtower ($cpt\u name), $opts);
\/\/New\u cpt\u job() actually calls register\u post\u type() at the bottom of the function and passes various parameters and labels defined in the process. If all goes well, you can now go to the back end and view the new home page of the content. The
If you select add new random quote, you must have a familiar interface to enter quotation marks. After quickly moving to the database, you will see that the quotation is saved as the correct custom post type. At this time, we can make all kinds of additional fine adjustments and changes, but that is, the extent to which the installment work of this series is completed. Although we haven’t deployed a lot of code, we have just completed another key step of the entire plug-in development. Moreover, WordPress plugin boilerplate has proved its value again by providing convenient code examples and solid structure for reference. The
While turning 9 in the second half of the conclusion series, we are constantly and systematically following the path of happiness. So far, we have selected several important boxes as the solid skapoldin to guide us, and are ready for the future division. Let’s summarize the main content of this lesson. WordPress introduces the concept of custom post types. We then performed the basic steps required to implement custom types. Finally, we used the existing code that guided us to determine whether to insert and work with custom content type registration in the existing settings. Now that you have a place to buy content, look forward to the next part of this series to learn how to actually display content. As always, if you have any questions or ideas, please feel free to contact and share the following comments! The
Recommended picture: garrot

Author:

Leave a Reply

Your email address will not be published. Required fields are marked *