Thord Daniel Hedengren - Smashing WordPress_ Beyond the Blog-Wiley (2014)

(avery) #1

CHAPTER 5 • The Child Theme Concept 123


/
Theme Name: Small Notes
Theme URI: http://tdh.me/wordpress/small-notes/
Description: This is Small Notes, a child theme for Notes Blog.
Author: Thord Daniel Hedengren
Author URI: http://tdh.me
Template: notes-blog
Version: 1.0
.
You need to have both Small Notes and Notes Blog in your wp-content/themes/
folder for this theme to work.
.
/


@import url("../notes-blog/style.css");


div#content { font-family: Georgia, Times New Roman, serif; }


ul.sidebar ( color: #333; }


Remember the Page templates you wanted? Creating them is easy. Just create them like you
would if you hacked the Notes Blog theme and put them in the Small Notes child theme
folder. Now they are available for use whenever the Small Notes child theme is activated, just
like with a regular theme.


Every template in the child theme is ranked higher than its equivalent in the parent theme.
This means that even though there is a sidebar.php in the Notes Blog parent theme, your
sidebar.php from Small Notes will be loaded instead. If you don’t want to make any changes to
the sidebar.php file from the parent theme, just don’t add that file to the child theme.


There is one exception to this rule, and that is functions.php. The parent theme’s functions.php
file will be loaded even if there is a functions.php in the child theme folder, but the child theme’s
functions.php is loaded first. This is a good thing because it means that you can use the child
theme’s functions.php to alter whatever features and functions you’d like from the parent theme.
In other words, if you want to do something slightly different in your child theme, you can
override parts of the parent theme’s functions.php by just altering the particular code that’s
bothering you in your child theme’s functions.php, leaving the rest of the parent theme’s
functions.php fully functional. The great advantage to this process is that only changes go in
your child theme, so whenever the original parent theme is updated, you can update your
parent theme too, knowing that your changes are intact in the child theme. Better yet, your child
theme will reap the benefits of the parent theme update, while otherwise remaining untouched.


THE BEAUTY OF TEMPLATE FILE OVERRIDING


The fact that most template files in a child theme will override the parent theme’s equivalent
means that you can target specific parts of the parent theme and alter just those. This usually
means that you’ll add new template files to your child theme that take precedence over the
parent theme. For example, say that you want another look and feel for your category
archives; you’ll just create the category.php template file in your child theme, and it will be

Free download pdf