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.
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.
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.
- We can create a child theme with just a folder, a style.css file and an screenshot image
- We can change only the styles in our child theme that we want to, without hacking any of the parents files
- We can create a functions.php file to add custom functions to our child theme
- We can switch off the parents functions in our child themes functions.php with remove_filter or remove_action
- 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
- When we need a new template page we copy the page.php to the child themes folder and create the page there
- We can add and call files or images from our child theme using STYLESHEETPATH or bloginfo(‘stylesheet_directory’)
- We do not need to worry about our changes being over written when we update the parent theme
- We have a smaller set of files to work with and less code to trawl through
- If we make a mistake we can refer back to the parents code as this remains untouched
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?
- Template Parts can be one or several lines and this way keeps the changes to the pages to a minimum
- Template Parts are easy transferable from theme to theme without having to search inside the parents files
- If we name template parts well they will be easy to remember, navigation-2, navigation-3 etc:
- We can add a collection of template parts with our theme, and add any one of these with one line of code
- We can save development time, this could make us more competitive and increase profit margins
- We can use template parts to introduce third party plugins that require code into our templates
- We can create a basic theme and offer enhancements for a fee which can be added in minutes
- If we structure our template parts correctly we do not need to change any code to use them in many different themes
- If we have a problem with a template part where a plugin stops working we can remove the call quickly
- 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.
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.
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.