# Development using Roots

**URL:** <https://discourse.roots.io/t/development-using-roots/72>\
**Category:** archived 🗄\
**Created:** [August 7, 2013, 9:24am UTC](https://discourse.roots.io/t/development-using-roots/72 "2013-08-07T09:24:13Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![iagdotme](https://discourse.roots.io/user_avatar/discourse.roots.io/iagdotme/32/6311_2.png) [@iagdotme](https://discourse.roots.io/u/iagdotme)\
**Post date:** [August 13, 2013, 2:10pm UTC](https://discourse.roots.io/t/development-using-roots/72/10 "2013-08-13T14:10:59Z")

</div>

Hi,  
The wrapper concept totally does your head in at first. It took me weeks to work out what was happening, but now I really love it. It means much cleaner code and funnily enough is easier to work with. However I totally feel your pain.

The problem for me was that I hadn’t got to grips with the standard WordPress template hierarchy which made getting my head round how Roots worked harder.

I don’t know whether this will help you or anyone else, but here are some notes (quite a bit taken from the WP docs as well) that I made up whilst I tried to get my head round it all…

* * *

**Standard WordPress set up**

Normally WordPress has the following template files:

- List item
- style.css
- header.php
- index.php
- sidebar.php
- footer.php
- single.php
- page.php
- comments.php
- 404.php
- functions.php
- archive.php
- searchform.php
- search.php

WordPress uses the Query String (which it gets from the URL of the current page on the website) to work out what template file or template files to use to generate the page.

Firstly WordPress works out what _type_ of page the current page is (i.e. is it a posts, archive, page, category or other page)

WordPress works out what template page or pages to use based on something called the Template Hierarchy.

WordPress firstly checks to see if it can find the most specific template file for its needs and if not it falls back to the default. For example it may check the category ID, slug, taxomony name or other criteria.

How WordPress checks depends on the type of page being requested. For example if the page being requested is a blog category page it will try the following:

1. It checks to see if there is a category template file for the current category. For example if the current category has an ID of 4, it will check to see if _category-4.php_ exists
2. If not it will check to see if the generic category template file, _category.php_ exists.
3. If that doesn’t exist it will check to see if the archive template exists- _archive.php_
4. If that doesn’t, WordPress will fall back and use the default _index.php_

Here are the queries depending on page type:

**Front Page**

1. **_front-page.php_** _(if doesn’t exist, falls back to…)_
2. **_index.php_**

**Home (Blog) Page**

1. **_home.php_** _(if doesn’t exist, falls back to…)_
2. **_index.php_**

**Single Post**

1. **_single-{post\_type}.php_**. If you are using custom post types you enter the slug of the custom post type- for example if the custom post type is “events”, this would be single-events.php _(if doesn’t exist, falls back to…)_
2. **_single.php_**

**Page**

1. custom page type (The Page Template assigned to the Page. You can create your own page templates (page-templatename.php for example) and select these on the edit page section). At the top of the page template you should put the template name in comments: /\* Template Name: Magazine \*/ _(if doesn’t exist, falls back to…)_
2. **_page-(slug).php_**\* (if doesn’t exist, falls back to…)\*
3. **_page-(id).php_** _(if doesn’t exist, falls back to…)_
4. **_page.php_** \* (if doesn’t exist, falls back to…)\*
5. **_index.php_**

**Category (“Category” is an example of a “taxonomy”)**

1. **_category-(slug).php_** _(if doesn’t exist, falls back to…)_
2. **_category-(id).php_** _(if doesn’t exist, falls back to…)_
3. **_category.php_** _(if doesn’t exist, falls back to…)_
4. **_archive.php_** _(if doesn’t exist, falls back to…)_
5. **_index.php_**

**_Tag_** (“Tag” is an example of a “taxonomy”)

1. **_tag-(slug).php_** _(if doesn’t exist, falls back to…)_
2. **_tag-(id).php_** _(if doesn’t exist, falls back to…)_
3. **_tag.php_** _(if doesn’t exist, falls back to…)_
4. **_archive.php_** _(if doesn’t exist, falls back to…)_
5. **_index.php_**

**Custom Taxonomies**

1. **_taxonomy-(taxomony)-(term).php_** _(if doesn’t exist, falls back to…)_
2. **_taxonomy-(taxomony).php_** _(if doesn’t exist, falls back to…)_
3. **_taxonomy.php_** _(if doesn’t exist, falls back to…)_
4. **_archive.php_** _(if doesn’t exist, falls back to…)_
5. **_index.php_**

**Archive**

1. archive-(post\_type).php _(if doesn’t exist, falls back to…)_
2. archive.php _(if doesn’t exist, falls back to…)_
3. index.php

**Author**

1. **_author-(nicename).php_** _(if doesn’t exist, falls back to…)_
2. **_author-(id).php_** _(if doesn’t exist, falls back to…)_
3. **_author.php_** _(if doesn’t exist, falls back to…)_
4. **_archive.php_** _(if doesn’t exist, falls back to…)_
5. **_index.php_**

**Search**

1. **_search.php_** _(if doesn’t exist, falls back to…)_
2. **_index.php_** _(if doesn’t exist, falls back to…)_

_404 (Page Not Found)_

1. **404.php** _(if doesn’t exist, falls back to…)_
2. **index.php** _(if doesn’t exist, falls back to…)_

Here are the main template files that usually come with a theme excluding headers, sidebars and other sections of pages:

- 404.php
- author.php
- base-front-page.php
- base.php
- category.php
- front-page.php
- index.php
- page-custom.php
- page-sample-page.php
- page.php
- single.php
- search.php

As well as the above there are sections of pages that the above pages can use to put together the page:

- header.php
- footer.php
- sidebar.php
- searchform.php

Finally there are some special files that need to be included:

- style.css (this gives WordPress the name and details of the theme. It can also be used for CSS styles)
- functions.php (special functions for the theme to use)

As well as the above you can now put in special template files that the template hierarchy can use for specific pages. For example a template for a specific category “category-(slug).php”

# ROOTS

WordPress usually puts all of the code and content into these template pages and fetches the header, sidebar and footer from the header.php, sidebar.php and footer.php files. Roots does away with all of that and uses base files to give the template structure. This means you can have different pages with different headers and footers. This changes the way the WP template hierarchy works slightly.

If the current page is the front page, WordPress would normally check for the front-page.php template. However, Roots runs some code that checks to see if there is a “base” file for that template. In this case it is looking for base-front-page.php. If that doesn’t exist it will look for base.php. The base file includes the header and footer and checks to see if the sidebar should be outputted, but actually you can get the base.php file to output whatever you like.

For example…

**Front Page**

1. **_base-front-page.php_** _(if doesn’t exist, falls back to…)_
2. **_base.php_**

**Home (Blog) Page**

1. **_base-home.php_** _(if doesn’t exist, falls back to…)_
2. **_base.php_**

**Single Post**

1. **_base-single-{post\_type}.php_**. If you are using custom post types you enter the slug of the custom post type- for example if the custom post type is “events”, this would be single-events.php _(if doesn’t exist, falls back to…)_
2. **_base-single.php_**
3. **_base.php_**

* * *

I hope that makes it clearer. It helped me…

_(edited to fix formatting)_

---

_[View the full topic](https://discourse.roots.io/t/development-using-roots/72)._
