In this Problem Solving lab, your website is broken, as the first post in the loop is exhibiting unexpected behavior. You want to reposition the post info (i.e. date and author’s name) above the title. It works on all of the posts except the first one. Why? In this active, hands-on lab, you and I will walk through how to find the root cause, why it’s happening, and then how to resolve it.
Here is what you expect to happen and it does except for the first post in the loop:
but this is what is happening on the first post:
Why is this happening? What is the root cause?
The purpose of this lab is to hone your problem-solving skills while teaching you more about PHP, Genesis, and WordPress core. I invite you to stop the videos and attempt to find the root cause on your own. Then work along with me as you and I walk through the problem and systematically let the system tell us where the problem lies.
Starting Point
Here is the wee bit of code that is intended to reposition the post info above the post title. Put this code into your sandbox project. For this lab, just put this snippet into your functions.php
file, as the sample theme does not have modular file structures. Place it at the very bottom of the file.
add_action( 'genesis_entry_header', 'reposition_post_info_above_entry_title', 1 ); | |
/** | |
* Reposition the post info above the entry title. | |
* | |
* @since 1.0.0 | |
* | |
* @return void | |
*/ | |
function reposition_post_info_above_entry_title() { | |
if ( ! is_front_page() && ! is_home() && ! is_archive() ) { | |
return; | |
} | |
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); | |
add_action( 'genesis_entry_header', 'genesis_post_info', 7 ); | |
} |
In order to do this lab, you will need the following:
- The free Genesis Sample theme or any Genesis-powered theme.
- The Genesis framework.
- Your local web server spun up and ready to go (I recommend DesktopServer).
- and your favorite IDE or editor open and ready.
Your best friend is code, Tonya is making the introductions.
Episodes
Total Lab Runtime: 01:16:42
- 1 Lab Introductionfree 02:47
- 2 Quick Explanationfree 10:13
- 3 Identify the Expected vs. Actual Behaviorbasic 05:28
- 4 Evaluate the Contributing Factorsbasic 12:40
- 5 Evaluate the Contributing Factors - Part 2basic 04:08
- 6 Putting in Our First Testspro 06:24
- 7 Fine-Tuning Our Testspro 08:40
- 8 Analyzing the Cluespro 12:36
- 9 The Root Causepro 09:06
- 10 Make it More Performant & Wrap it Uppro 04:40