The next thing we’re going to do is talk about this custom_loop that was created for this example and it has some main parts.
The first part is this constructor and what it does is it calls the parent custom_loop and gets all the information from the parent custom loop which is thesis_custom_loop. If we go take a look at thesis_custom_loop here for just a second, look under the library, under classes and look under loop.php, thesis_custom_loop is down here towards the bottom.
The first function inside of it is anything out there called custom_loop and it has some filters that allow you to force Thesis to ignore settings in design options and just generate your hard coded CSS which is something we’re not going to use. It has this ability to command and reset some things at the very beginning. That’s the first thing it does, it goes to that and gets that part started.
Set of Functions Added to the Init Hook
The next thing it does is it adds a set of functions to the init hook. An init hook is a WordPress hook that fires very early on in the page rendering process. At the init hook it says, “Okay, process the init function”, and the init function says, “Process these actions and these filters”.
These actions refer to this function actions. These filters refer to these function filters and essentially what it says is that, at the init hook, “Process all of the actions that are in here, process all of the filters that are in here”. Once it has gone through the construct, the init and processed all the functions inside of that, then it goes on to the next set of custom_loop functions. These functions are functions that you can define.
Last week, we took out the thesis_home_loop and replaced it with Hello World. We actually aren’t going to use that ability of Thesis so we’re going to remove this entirely from this loop here. We’re also going to rename the class because the thesis_child_theme_example name is far too generic.
Creating a New Class that Extends the Existing Class
What we’re going to do instead is call this crtc_child_thesis_loop. We’ve created a new class that extends this existing class and we’ll talk about that later some time and we’ve instantiated that class by calling it new. We’ve given it a better name. He used a very generic name that I don’t think was appropriate in our case, we need to use our unique identifier at the beginning of it and then make it more descriptive.
So, the crtc_child_thesis_loop extends the thesis_custom_loop, we’ll keep that constructor in there, we’ll continue to process actions and filters at this init but we’re not going to do any custom loop inside of this.
Place the Add Actions and Remove Actions Inside the Loop
The next thing we’ll do is take these add_actions and remove_actions and we’re going to place them inside the loop.We’re going to place them in the order in which they will appear so this after_switch_theme is a hook that fires much earlier than these two do so we’ll put them below.
The reason for doing this, remember I showed you a launch.php which is where they put all their add_actions and remove_actions? We’re going to put all of our add_actions and remove_actions inside of the custom_loop at this init stage. That’s why we’re going to include them in here.
Reorganize File Structure
The other thing we’re going to do is take this class entirely out of the functions file and we’re going to create a brand new file for that. We’re going to do that under classes, I’m going to create a new file and that’s going to be called crtc_loop. We’re going to delete this ending tag and we’re going to place our class definition here so now we have class crtc_child-thesis_loop extends thesis_custom_loop then we need to make sure we include this file.
We come back over to our functions, we’ll require once and instead of CRTC_FUNCTIONS, it’s going to be CRTC_CLASSES and instead of crtc_header.php, it’s going to be crtc_loop.php. We’re just going to delete that and we’ll upload functions, we’ll upload lib, we’ll upload classes and our website should be working just fine now.
What we just did there is reorganize the file structure. We took our functions.php file and we’re just putting definitions in functions.php; otherwise, we’re calling other files to do the rest of these things.
We call the header.php to create our header, we called the loop.php to put that thesis_custom_loop in and as we continue to add new structure to the site, we will continue to add more includes and even some more definitions.