Skip to content

Template Hierarchy

Jim Reevior edited this page Aug 14, 2018 · 1 revision

Template Hierarchy

Page templates

Page templates should contain all of the logic for displaying the content.

A page template can come in two forms.

  1. One that contains Template Name: in the file's docblock and is selectable in the admin.
  2. One that is used by WordPress core and not selectable in the admin, such as archive-profile.php.

Sections

A section is a repeatable part of a page that contains logic and most likely uses template parts to display content.

A great example of a section is a Related Posts. This could appear on multiple pages in multiple contexts, but it will mostly be the same. It will contain the logic (querying related posts and looping through them), but it will call get_template_part( get_post_type(), 'related' ) or r_get_template_part( get_post_type(), 'related' ) to display the actual content.

Template Parts

Template parts are small, repeatable chunks of code that represent individual pieces of content. This should contain little to no logic. It is strictly for displaying a single piece of content.

Rule: Template parts representing post types should use the post type name. Example: the degree_program post type template parts should be named starting with degree_program.

Exceptions

There are a few exceptions to this organization.

Single Post Type Templates

If the template is single-custom_type.php, for example, it is OK to not use a template part here as long as the same markup and post content is not repeated somewhere else.

Welcome to Responsive!

Get started

Configuration

Build child themes

Sass

Javascript

PHP

Shortcodes

Templates

GitHub

Tasks

Contribute to the framework

Code Examples

BU Developer Resources

Clone this wiki locally