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.
Lab Introduction
Let me introduce this hands-on code building lab to you. You and I are going to build this lab together. Our goal is to remove the site footer from your Genesis child theme. We’ll build four (4) different implementations which accomplish virtually the same result. We’ll talk about the pros and cons of each strategy and when to use one over the other. It’s best that you do this lab with me. You will learn more when you actually write the code, explore the Genesis framework with me, and see what happens as you make changes. Instead of just watching […]
Remove the Genesis Site Footer on Home Page
Let’s remove the default Genesis site footer on the posts’ page, i.e. the home page. In this hands-on lab, you will walk through four (4) different implementations, each of which removes the site footer. You’ll discover the pros and cons of each of these approaches. From this exercise, you’ll be able to select the best approach for your specific needs.
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.
Serve Archive Template from the Plugin
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 […]
Plugin Architecture
Let’s talk about the architecture and intent. While you could build a home.php or page_blog.php template, this plugin is portable and modular. It allows you to move it from project-to-project without having to change the theme. It uses the built-in WordPress editor, which your client is used to using. We are not using a widget because widgets are cumbersome for clients. A widget does not have the editor interface. It’s not as intuitive for the site owner to figure out where to put content when you use widgets instead of the page itself.