Ten Good Reasons to use WordPress Child Themes and Template Parts

We are really getting into the WordPress 3 child themes and template parts, they can cut down the workflow and time to market for theme developers, learning to use WordPress child themes and template parts can give you the edge and make you more competitive.

If you are just starting out or been working with WordPress for years and not looked at WordPress child themes and template parts, here our our views on why you should take the time to look at how they can be used.  

child-and-template2

We have just created the first set of tutorials for Word Press 3 and the twenty ten theme.

When we created our Artisteer Themes we exported a full set of files every time, as we built up a collection of features and functions for our themes we were constantly adding these to our new generated themes. 

We added things like a search box in the menu bar, social media icons, clickable regions, added slideshows and new widgetized areas, we found ourselves copying blocks of code to merge into our newly generated themes, this all took time and if we were working on a theme for a customer, time is money.

For anyone that has no idea about child themes and template parts we will do a summary section and ten reasons why you should be using them.

Child Themes

This was well summed up over on the Artisteer forum, the person who made this analogy is now a convert to child themes and is using them on a daily basis.

As I understand it, by analogy, the “parent” is right-handed (templates) and as a result all the children are right-handed, the parent is blonde (styles) so all the children are blonde, and the parent can run at 10 miles per hour (functions) so the children can, too.

Now if the parent has 5 children (5 child themes – 5 for no particular reason) , there are 5 right-handed blondes who can run at 10 mph, but if I want one child to be brunette I can do so by changing that child without changing the parent or other children, if I want another one to be left-handed and redheaded I can again do so by changing that child without changing the parent or other children, and if I want one to sprint at 15mph, the same applies.

In the reverse, however, if the parent is suddenly enabled to run at 20mph the existing children also get that increased ability.
Now here’s my question, can we upgrade our legacy themes by making them a child of the default twenty-ten, and have our parent twenty-ten remove the unneeded function actions of our child themes?

What a great analogy, the parent can be any WordPress theme, but if the parent was twenty ten then the children would inherit all of the parents genetics and blood line.�
WordPress themes and Artisteer themes are different blood lines but both are both descendents of the WordPress family, and inherit attributes from WordPress, and now we are only looking at how twenty ten presents itself and acts, and we like what we see.

So we can take some or all of parent themes better behaviours and instil them in our child theme, the parent will still be the same but the child will develop in their own right, but as a more functional and integrated entity, we may not need to change the whole child but just some actions, we can do this without upsetting the parent.

As you see the parent can have many children each with their own personality, but they will have all the parents attributes to call from and we just add other influences from outside the immediate family, some of these we may not like and we can just replace them or turn them off!, child themes are becoming more current and the correct way to work with WordPress.

  1. We can create a child theme with just a folder, a style.css file and an screenshot image
  2. We can change only the styles in our child theme that we want to, without hacking any of the parents files
  3. We can create a functions.php file to add custom functions to our child theme
  4. We can switch off the parents functions in our child themes functions.php with remove_filter or remove_action
  5. When we want to change a default page layout, we copy the file from the parent and make the changes in the child themes folder
  6. When we need a new template page we copy the page.php to the child themes folder and create the page there
  7. We can add and call files or images from our child theme using STYLESHEETPATH or bloginfo(‘stylesheet_directory’)
  8. We do not need to worry about our changes being over written when we update the parent theme
  9. We have a smaller set of files to work with and less code to trawl through
  10. If we make a mistake we can refer back to the parents code as this remains untouched

Template Parts

Template parts are a new addition to WordPress 3, if you have looked at the twenty ten theme you will see a new structure the the pages, the loop code is gone and been replaced by a single line of code.

WordPress 3 is more compact and by using template parts we can now have libraries of reusable template code, we can package additional sidebars, slideshows, social icons, custom loops, search boxes, logon boxes etc:, and call these in any of our theme pages.

The time we can save by using template parts is huge, we can now add a section to our page with a call like, <?php get_template_part( ‘slideshow’, ‘smoothslider’ ); ?>, this could be any theme part, need a second or a second or third menu then <?php get_template_part( ‘navigation’, 2 ); ?>

What does <?php get_template_part( ‘navigation’, 2 ); ?> do you may be wondering, well WordPress will look first in the child themes folder and then in that parent themes folder for a file called navigation-2.php, so we could have a number of these calling different sub menus, we could have a number of predefined slideshows, Smooth Slider, cu3er, Dynamic Content Gallery etc:, when a new one comes along we just create a new template part to add to our library.

Template Part holds the theme parts and any required code, this could be a few lines or many lines, and we can add these to our themes pages with one line of code, how cool is that?

  1. Template Parts can be one or several lines and this way keeps the changes to the pages to a minimum
  2. Template Parts are easy transferable from theme to theme without having to search inside the parents files
  3. If we name template parts well they will be easy to remember, navigation-2, navigation-3 etc:
  4. We can add a collection of template parts with our theme, and add any one of these with one line of code
  5. We can save development time, this could make us more competitive and increase profit margins
  6. We can use template parts to introduce third party plugins that require code into our templates
  7. We can create a basic theme and offer enhancements for a fee which can be added in minutes
  8. If we structure our template parts correctly we do not need to change any code to use them in many different themes
  9. If we have a problem with a template part where a plugin stops working we can remove the call quickly
  10. Using template parts will make it easy to find the page changes if the parent theme is updated

We that is our summary, feel free to leave a comment, if you are not working with child themes and would like to start, then this is a good place to be as we have a number of tutorials for you to work through.

Notices

We do require your feedback to improve our themes and tutorials, please leave your comments good or bad.

Code disclaimer information

If this document contains programming examples, www.DigitalRaindrops.net grants you a nonexclusive copyright license to use all programming code from which you can generate similar functions tailored to your own specific needs.

All sample code is provided by http://DigitalRaindrops.net for learning illustrative purposes only.

These examples have not been thoroughly tested under all conditions. www.DigitalRaindrops.net, therefore, cannot guarantee or imply reliability, serviceability, or function of these examples.

All programs contained herein are provided to you “AS IS” without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.

Membership

Registration and Membership is no longer required for downloading files or interacting with Digital Raindrops, posting a comment or topic in the forum does use Captcha to reduce spammers.

This website is a tool to support and promote WordPress and Artisteer theme development, please support, share and give credit for any benefits you gain from the tutorials on this website.

6 thoughts on “Ten Good Reasons to use WordPress Child Themes and Template Parts

  1. There was a discussion in the Artisteer forums about child templates not overriding a parent template:
    http://www.artisteer.com/Default.aspx?post_id=143000&p=forum_post&forum_id=13

    The problem was that Artisteer was not checking for the template in the child, but only in the parent, so changes in the child were ignored. User Abland came up with a solution to replace the problem in “parent_theme/core/parser.php” by placing a new function in the child “child-theme/functions.php” for ‘art_parse_template’. See the above link for full details.

  2. Dear David,

    Tim here again, maybe if I explain what I’m looking for you could lead me in the right direction.
    Were creating a membership site for new and upcoming artists in the music industry and want to use wordpress as the base.

    The artist pays for a membership, the membership includes many features such as live streaming of his or her music and to include video streaming.

    We want to be able to customize the look of each members page, and the ability to allow the artist to post what ever they want on this page and the page would have a different sidebar from all the rest which he could put any widget they want in that sidebar.

    Can this be done using child themes?
    thanks

    • Hi Tim,
      Ok the way it could work is to use WordPress in multi-site mode, then each artist has a sub domain (blog) or sub folder site.

      So you then have what we have here on this very website, http://investica.digitalraindrops.net where investica is the artists name and shares the same database tables but has a different content and theme.

      So in the Investica (artist) admin area the artists can add what we allow sidebar widgets, pages, posts, we can choose a theme or have a “theme set” for the artist to choose from (no upload allowed) for their website space.

      This would be a good example of where the child themes could work, have a master functions theme and a number of child themes with different colors and layouts, let the artist pick from a set of themes, and charge to add in more features or to customize.

      On the front page of the main website you could aggregate content from the sub domains etc:

      To use top sub domains like mine the website must have a static IP, or you can use subfolders like DigitalRaindrops/Investica/ which do not look half as nice. 

      HTH

      David 

      PS: If you have a band with no name I have a nice domain registered “Urban Upheaval” (.com, co.uk, and .net) that is looking for a buyer! :)

      • Dear David,

        I noticed while viewing the above website, that the main page was different from the internal pages, basically in the header, was this done with a child theme or did you create a different page template for the internal pages.

        either way would you mind explaining how you did this, maybe in a separate email, I’ve been having some difficulty with this in regards to using Artiseer. tdcaron[at]verizon.net

        Thanks Tim

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Connections

Connect with Us
Follow Digital Raindrops on Twitter Join Digital Raindrops on Facebook
Share

Related Posts

Posted in Blog

Read More