In the last episode, you wrote the code to serve the archive template for the FAQ custom post type from the plugin. Now we need to allow the theme to override. If a developer wants to change the archive, s/he could add an archive-faq.php file to their theme. In that case, you’d want to load their template instead of yours. Give the power to the theme over the plugin for templates. There are a couple of approaches to accomplishing this feature. You’ll first build a solution with Technique 1 that locates the template, and if not available, it then returns […]
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.
Test, Fix, Commit, and Wrap
Now let’s walk through and test our module. In doing so, you’ll find that we need to change the taxonomy’s registration as we don’t want to show it on the front-end. Let’s make that change. Then we’ll commit the final changes to your GitHub repository. I have to say how proud I am of you! Seriously! You worked right along with me. I know it was a long lab. The whole point was to walk you through the entire process of building a new feature module, step-by-step. I hope you learned about WordPress, PHP, Plugins, HTML, and more. We covered […]
Review and Commit Changes
Let’s talk through what you’ve accomplished in the archive template episodes. You’ll add another FAQ too. Then let’s commit the changes to your GitHub repository. You’ve made a lot of changes. It’s time to commit them.
Set the Order Within the Topic
Remember that one of the requirements is to add the ability to set the order for the questions within each topic. For the custom post type, we added the page attributes feature in order to gain access to the menu order. In this episode, let’s change our SQL to order by both the term ID and the menu order. We’ll also take a look at the database too. You’ll be amazed at how easy it is now to add this feature.
Build the Archive Views
In the last episode, we built the boilerplate code for doing the Loop. Now it’s time to build the view files. We’ll reuse the QA shortcode view file. But remember that there could be more than one FAQ. We’d want to have the <dl> container outside of the view file. Plus we will want to display the topic too. Let’s do that in this episode. You will learn about how to process two different view files. The goal is to maintain the intent of the business logic and the view file. Therefore, we do not want to loop and process […]
Build the Archive
Let’s build our archive template now. We are going to need to fetch the records from the database that are already grouped by their topics. To do this, let’s reuse the code from the Advanced SQL lab. You can get the code here on GitLab and load it into the archive file. Here is the lab to refresh yourself on how this code works, as I’m not going to re-explain in this episode. We’ll see what we get back and then adapt the code for our needs.
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.