We all know that looking over a long list of ToDo’s can be stressful, and that GTD comes our rescue by getting us to organize those lists by contexts (Home, Office, Computer, Errands, Calls, etc). Although we wind up with a few lists instead of one, the lists are much shorter and we only pay attention to the list that fits the context we are in. Marvelously helpful in reducing stress.
Today I came across someone’s Thesis Theme Design that uses some of the sort of modularity that GTD does, and it is motivating me to make some changes to my design that I had been putting off (nothing major … just little tweaks).
I had been avoiding making the changes, I think, because my custom_functions.php file is getting “cumbersome.” It has several functions in it, and most of them are long, and I think I have just been avoiding wanting to make any additions to it for fear of making it even more cumbersome.
For example, here is one of my shorter functions:
function custom_ebook_promo() {
if ( !is_page('downloads') && !is_page('contact') && !is_page('donations') && !is_page('archives') && !is_page('my-music') && !is_page('free-ebook-download') ) {
$html = '
<li class="widget">
<div class="widget_box">
<p class="remove_bottom_margin">Download our <a href="http://www.keenerliving.com/downloads/free-ebook-download/">Time Management eBook</a>. Filled with useful tips for technology users.</p>
</div>
</li>
';
echo $html;
}
if (is_front_page() ) {
$html = '
<li class="widget donations">
<ul>
<li class="donate"><a href="http://www.keenerliving.com/donations/"><b>donate</b></a></li> </ul>
</li>
';
echo $html;
}
}
add_action('thesis_hook_before_sidebar_1', 'custom_ebook_promo');
But Mitch uses a more modular approach, splitting some of the functions out into separate files, as illustrated in the following example from his custom_functions.php file for the Thesis-ified Neoclassical Theme:
function custom_header() {
include (TEMPLATEPATH . '/custom/rotating_header.php');
}
add_action('thesis_hook_header', 'custom_header','99');
Notice that he has split the rotating header code out into a separate file. Clever, eh?
So I will be doing some of that with my Thesis implementation. I should have thought of doing this on my own, as I am not totally unfamiliar with modularizing code. But, none of us thinks of everything that we should, so it’s wonderful that we get to learn from each other.
By the way, for Thesis users who are wondering if this undercuts one of Thesis’ advantages, that of having all custom code in one spot, the answer is: it does not undercut it at all. The added files are still kept in the custom folder, along with custom_functions.php and custom.css (and the custom images folder).
For those of you who could care less about website design modifications, the principle (and value) of breaking big things into smaller, more manageable ones can apply to a lot of things if we only take the time to think about applying it.
Great post, Bruce.
I agree modularizing your custom files, especially you’re custom_functions, is a great way to keep organized with Thesis.
The CSS, I must admit, is a bit untidy in version 0.1, but with the custom_functions we’ve followed the principle of working top-to-bottom through the page and then including pages for specific functions at the bottom (of which I don’t believe in this case there are any!).
Modularizing is particularly effective for more complicated functions. At DIYninjas for example, we’ve put things like our fat-footer which requires a fair bit of custom PHP in it’s own file.
That’s not all you can do with modularization though: for one of our clients running WPMU we can call specific custom PHP and CSS according to blog_ID so they can run similar websites of the same Thesis core, with just about any changes they like containing within isolated custom files.
All in all, it’s a sweet way of working!
I agree. It’s a top way to handle things.
You don’t even have to put it in a function. I have some functions (and add_actions) in another file (e.g. custom_photoblog.php) and then use
include (custom_photoblog.php);Good points, kristarella.
I might put all of my sidebar stuff in one file, now that you mention that I can include add_actions in the file, too.