There are two things that make working as a WordPress theme developer really easy and tasty: Child themes and the WordPress template hierarchy. Both save you a lot of time and nerves. At least most. Unfortunately, there is exactly one point at which both together become a problem: If a parent theme contains a template file that you do not want to use in the child theme at all. To understand the problem (and its solution) in more detail, I have to go back a little:
The WordPress theme hierarchy
In order to be able to develop a WordPress theme, you only need two files: one the style.css (theme information and styling) and one index.php (markup and functionality). Although one should as far as possible the functionality into the functions.php outsource, but this is not mandatory. The two files mentioned above are enough to get a working WordPress theme up and running. The index.php is used as a template for all pages, postings, attachments, etc.
If you want to set up a special area a little differently, you can create a more specific template file. Eg: takes care of the singular.php fileabout all the individually displayed elements, i.e. a single page, a single post, a single attachment, etc. If I now create a file with the name page.php , it only takes care of a single content page, but not a single article. In the end, you can become so specific that you create a completely separate template for a single page with a special ID ( page-ID.php ).
So you can start quickly and easily and then, if necessary, become specific down to the smallest detail.
WordPress Child Themes
Another advantage of WordPress are so-called child themes. here are just a few sentences about child themes: You can outsource all changes to a parent theme in child themes . The parent theme remains updateable and changes made once are not overwritten. This is especially useful if you want to make small changes yourself, but the actual parent theme is continuously being developed by third parties.
The problem: Parent themes with a large number of specific templates
If you now use a parent theme with a lot of specific templates and want to create a child theme for it that has much fewer differences, things get a bit tricky. For example, if you create an index.php file in the child theme , it will not be used if the parent theme has a more specific home.php . So you also have to create a home.php file in the child theme , even if it should have exactly the same content as the index.php . And so it goes on happily. And if you change something in one file, it has to be changed in all the others too. If you are now working with a larger theme framework, it can quickly turn out to be several dozen files.
The solution: insert one file into another with get_template_part
Let’s take the example above: We only need one index.php in our child theme . Our parent theme also comes with a home.php . So that we don’t have to maintain two different files, we still create a home.php file in our child theme directory, but only add the following:
<?php // Overwrites the parent themes home.php with child themes index.php get_template_part( 'index' ); ?>
Now the home.php file of the child theme is correctly found and loaded, but this does nothing other than output the content of the index.php .
Once created, we no longer need to worry about home.php .
Comment for more about wordpress gigs,