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 has an
archive-faq.php in it.
Do you understand how WordPress loads the right template file from the theme? Let’s talk about the calling sequence:
- WordPress looks for a
archive-faq.phpfirst in the child theme (if there is one). If it finds, it loads it. Else, go to the next step.
- It looks in the parent theme. If it finds it, that one loads. Else, continue.
- It looks in the child theme for
- If no, it looks in the parent for it.
- If no, next it looks for
In this episode, I’ll show you the order that it looks for the template files. We’ll look at a child theme and the Genesis framework. But it works the same for any theme.
Who needs copy/paste? Right. Writing code from scratch is fun!
Total Lab Runtime: 05:11:56
- 1 Lab Introductionfree 07:51
- 2 Planning it Outfree 11:05
- 3 Module Architecturepro 17:12
- 4 Build the Basic FAQ Custom Post Typepro 06:04
- 5 Configuring the Custom Post Type Labelspro 18:33
- 6 Configuring the Custom Post Type Feature Supportspro 07:23
- 7 Configuring the Custom Post Type Optionspro 11:27
- 8 Flushing the Rewritespro 09:44
- 9 Planning the Taxonomypro 04:54
- 10 Build the Taxonomypro 05:33
- 11 Taxonomy Label Generatorpro 14:23
- 12 Flush Rewrite Rules - Taxonomypro 05:36
- 13 Architecting the Archive Pagepro 11:14
- 14 Serve Archive Template from the Pluginpro 10:41
- 15 Let Theme Override Our Archive Templatepro 21:29
- 16 Build the Archivepro 11:09
- 17 Build the Archive Viewspro 13:23
- 18 Set the Order Within the Topicpro 03:44
- 19 Review and Commit Changespro 02:34
- 20 Architect the Shortcodepro 15:23
- 21 Build the Shortcode - Single FAQpro 21:19
- 22 Fixing the Architecturepro 08:00
- 23 Define a WP_Query for Topicpro 16:10
- 24 Continue Building the Shortcodepro 11:39
- 25 Finish by Topic Shortcodepro 08:51
- 26 Planning the Refactorpro 08:01
- 27 Refactor FAQ Modulepro 19:58
- 28 Test, Fix, Commit, and Wrappro 08:36