Out-of-the-box, WordPress gives you built-in taxonomies which are used to group like or similar content together. You use categories and tags to add contextual information about the content and give readers additional mechanisms to explore and discover. In this hands-on lab, you will interact with and change the built-in taxonomies. This is an introduction to taxonomies, which will prepare you for building your own custom taxonomies.
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 […]
Define a WP_Query for Topic
For the feature that fetches the FAQs by a specified topic, we need to build a custom query. WordPress provides the ability for us to configure what we want using WP_Query. Let’s walk through the configuration parameters and figure out what we need to build a query that is based upon a certain post type, taxonomy, and term slug. We’ll use the reference guide from Bill Erickson to explore the needed configuration parameters. We’ll also take a look in WordPress Core at the WP_Query class construct and talk a little bit about PHP OOP.
Fixing the Architecture
Sometimes you go down a path with your architecture and then discover that it doesn’t fit your needs. It’s good that the problem happened, as now you and I can walk through the process of fixing the architecture. Let’s talk through the thought process of fixing the architecture. It’s a good exercise of how to re-think your code and approach.
Build the Shortcode – Single FAQ
Let’s start building the shortcode processor for the single FAQ, i.e. when the shortcode user-defined attribute specifies a single post ID to display. You and I will look at what we receive as user-defined attributes when processing the shortcode. We’ll look at the configuration parameters. We’ll think about different scenarios of how to process when we don’t receive a post ID or topic as well as when we receive an invalid post ID. This episode is heavy PHP fundamentals. We’ll talk about: ternary operator variable scope variable scope when including a file type casting from string to integer data type […]
Architect the Shortcode
The feature from the product backlog says that we need to develop a shortcode that embeds a single FAQ or a group of FAQs by a single topic. Hum, how are we going to accomplish this with one shortcode? We can use the user-defined attributes to let the author tell us which one to process. We can do the following: [faq post_id=”43″] [faq topic=”billing-and-payments”] Therefore, we are building a faq shortcode with two different user-defined attributes: post_id and topic. How are we going to process these two different requests? For the single FAQ, we get the post ID. Therefore, we […]
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.