In this episode, you and I are going to write the code that tells WordPress to load our archive template. Remember, out-of-the-box, WordPress doesn’t look in the plugins for templates; rather, it only searches the theme. Right? I showed that to you in the last episode. Therefore, we have to write the code that tells WordPress to load our file. Let’s dive into WordPress Core and look at how WordPress looks up and finds the template to load. We’re searching for a filter hook to use. You’ll look at get_archive_template() which is in wp-includes/template.php. Then you’ll build a helpers file […]
Labs
Labs are hands-on coding projects that you build along with Tonya as she explains the code, concepts, and thought processes behind it. You can use the labs to further your code knowledge or to use right in your projects. Each lab ties into the Docx to ensure you have the information you need.
Each lab is designed to further your understanding and mastery of code. You learn more about how to think about its construction, quality, maintainability, programmatic and logical thought, and problem-solving. While you may be building a specific thing, Tonya presents the why of it to make it adaptable far beyond that specific implementation, thereby giving you the means to make it your own, in any context.
Architecting the Archive Page
We want our plugin to provide a default archive template for the FAQ post type. This archive will group the FAQs by their topic and provide the HTML structure for each FAQ. We can’t expect theme developers or customizers to build this template for us. That’s not a reasonable expectation. Instead, we need to build the template and then serve it up. But WordPress does not serve templates from plugins out-of-the-box. Therefore, we will need to write the code to tell WordPress: “Hey, load this template please.” We’ll want to provide the means for the theme to override when it […]
Taxonomy Label Generator
What if you had multiple taxonomies? Think about that. What if you needed to add a “topic” and “faq-categories” for example? Using the current code, you’d copy the label generation code and copy it into the next taxonomy you are registering. That’s a lot of code. Instead, let’s build a label generator. Then you can call this function for any of your custom taxonomies. The code remains the same. The only thing that changes, typically, is the specific name. Why do this? It makes your code more readable and reusable. It speeds up your development time and reduces your costs. […]
Flush Rewrite Rules – Taxonomy
Right if you were to view one of the new terms, you’d get a 404. Why? Think about it. Why does it give you a 404? Because you need to flush the rewrite rules. You can do this by going to Settings > Permalinks and clicking on “Save Changes” button. But for a real plugin, you won’t want to have your customer install, activate, and then have to go to Settings in order to get the taxonomy and custom post type to work. Right? Instead, you want to handle it within the plugin. In this video, you’ll add the taxonomy […]
Build the Taxonomy
In this episode, you and I are going to build the custom taxonomy code. We’ll use the code from the Team Bios plugin that you built in the Custom Taxonomy Basics lab. I want to show you just how easy it is to take boilerplate code and then configure it for another custom taxonomy. It literally will take you less than a minute and then bam, you have a custom taxonomy.
Planning the Taxonomy
We need a way to categorize the content within the FAQs. Right? Categorization allows you to group the FAQs together for displaying them. For example, look at our Help Center. Each article is grouped and then displayed by a specific topic. We have Pre-Sales, Billing and Payments, and more. These topics are terms. These terms are bound to a custom taxonomy. Therefore, we want to build a custom taxonomy. Let’s call it “topic.”
Flushing the Rewrites
Now we need to handle flushing the rewrites when our plugin is activated or deactivated. We covered this topic in the Flush Rewrite Rules of the Custom Post Type Basics lab. In that episode, I showed you why you never ever want to flush the rewrite rules after your register a custom post type. Where should we put the activation and deactivation callbacks? Hum. Let me show you a couple of different strategies. As this is a module, we’ll opt to add the callbacks within the module itself. Why? It keeps everything together when you reuse this module. Pop Quiz […]
Configuring the Custom Post Type Options
Next, our custom post type needs further options to be configured, such as the menu icon and archive. Let’s walk through the different options.
Configuring the Custom Post Type Feature Supports
Out-of-the-box, when you register a custom post type, the feature supports are title and editor. That’s it. Hum, what if there are additional supports that you want, such as SEO or other custom ones from other plugins? If you have the Genesis framework installed, then it adds 3 feature supports. If you are using Yoast SEO, then it adds 1 feature supports. How do you specify these features when you build your plugin? You use the configuration code that you wrote in Exclude Post Type Features episode, as part of the Custom Post Type Basics lab. That code is reusable […]
Configuring the Custom Post Type Labels
The arguments for registering a custom post type are configurable to customize the experience and implementation for your needs. Part of that configuration are the labels. The labels are in the back-end. By default, they will use ‘Post.’ Hum, that will not make sense for the user, content strategist, and anyone who is in the back-end adding, editing, or managing the content. Our job is not just to write code. Nope, you are building experiences. It’s our job to make sure what we build is self-documenting, user-friendly, and draws people in to want to use it. Configuring the labels customizes […]