SlideShare a Scribd company logo
Wrangling theWrangling the
WordPress Template HierarchyWordPress Template Hierarchy
Like a BossLike a Boss
Let's start from the top!Let's start from the top!
index.phpindex.php
The FreelancerThe Freelancer
What is the WordPress TemplateWhat is the WordPress Template
Hierarchy Anyway?Hierarchy Anyway?
What is the WordPress TemplateWhat is the WordPress Template
Hierarchy Anyway?Hierarchy Anyway?
What is the WordPress TemplateWhat is the WordPress Template
Hierarchy Anyway?Hierarchy Anyway?
A theme is made up of many template parts.
What is the WordPress TemplateWhat is the WordPress Template
Hierarchy Anyway?Hierarchy Anyway?
A theme is made up of many template parts.
v
What is the WordPress TemplateWhat is the WordPress Template
Hierarchy Anyway?Hierarchy Anyway?
A theme is made up of many template parts.
That work together to create the pages and posts
that are viewable by the site visitors.
v
What is the WordPress TemplateWhat is the WordPress Template
Hierarchy Anyway?Hierarchy Anyway?
Query Power!Query Power!
Let's start from the top!Let's start from the top!
Let's start from the top!Let's start from the top!
index.phpindex.php
Let's start from the top!Let's start from the top!
index.phpindex.php
The FreelancerThe Freelancer
The Basic LoopThe Basic Loop
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//
// Post Content here
//
} // end while
} // end if
?>
index.phpindex.php
We're Hiring!We're Hiring!
We're Hiring!We're Hiring!
singular.phsingular.ph
pp
We're Hiring!We're Hiring!
singular.phsingular.ph
pp
We're Hiring!We're Hiring!
singular.phsingular.ph
ppSince WP 4.3Since WP 4.3
Meet the new employees!Meet the new employees!
Meet the new employees!Meet the new employees!
page.phppage.php
Meet the new employees!Meet the new employees!
page.phppage.php
Meet the new employees!Meet the new employees!
page.phppage.php
single.phpsingle.php
Meet the new employees!Meet the new employees!
page.phppage.php
single.phpsingle.php
Meet the new employees!Meet the new employees!
page.phppage.php
single.phpsingle.php
archive.phparchive.php
Meet the new employees!Meet the new employees!
page.phppage.php
single.phpsingle.php
archive.phparchive.php
Meet the new employees!Meet the new employees!
single.phpsingle.php
Wrangling the WordPress Template Hierarchy Like a Boss
single-book.phpsingle-book.php
single-book.phpsingle-book.php
Wrangling the WordPress Template Hierarchy Like a Boss
Wrangling the WordPress Template Hierarchy Like a Boss
archive-book.phparchive-book.php
archive-book.phparchive-book.php
The TeamThe Team
Wrangling the WordPress Template Hierarchy Like a Boss
The SpecialistsThe Specialists
The SpecialistsThe Specialists
front-page.phpfront-page.php
The SpecialistsThe Specialists
front-page.phpfront-page.php
The SpecialistsThe Specialists
home.phphome.php
The SpecialistsThe Specialists
home.phphome.php
Template PartsTemplate Parts
Template PartsTemplate Parts
header.phpheader.php
Template PartsTemplate Parts
header.phpheader.php
sidebar.phsidebar.ph
pp
Template PartsTemplate Parts
footer.phpfooter.php
header.phpheader.php
sidebar.phsidebar.ph
pp
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//
// Post Content here
//
} // end while
} // end if
?>
Your Basic LoopYour Basic Loop
<div>
<p>Something awesome goes here</p>
</div>
<div>
<p>Something really awesome goes here</p>
</div>
Your Static HTMLYour Static HTML
Very VersatileVery Versatile
loop.phploop.php
funstuff.phpfunstuff.php
mailchimp.phpmailchimp.php
content.phpcontent.php
<?php get_template_part('$slug'); ?>
Call To ActionCall To Action
Wrangling the WordPress Template Hierarchy Like a Boss
<?php get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'template-parts/section-home-visit', 'section' ); ?>
<?php get_template_part( 'template-parts/section-home-book', 'section' ); ?>
<?php get_template_part( 'sidebar-home', 'sidebar' ); ?>
<?php endwhile; // End of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_footer(); ?>
Parts Making the WholeParts Making the Whole
<div id="school-visit" class="section">
<div class="school-visit-text section-text">
<h2><?php the_field('school_visit_header'); ?></h2>
<p><?php the_field('school_section_text'); ?></p>
<p class="call-to-action"><span><a href="<?php
the_field('school_visit_button_page_link'); ?>"><?php the_field('school_visit_button_text'); ?
></a></span> <?php the_field('school_visit_after_button_text'); ?></p>
</div>
<?php $attachment_id = get_field('school_visit_image');
$size = "home-school-visit"; // (thumbnail, medium, large, full or custom size) ?>
<?php echo wp_get_attachment_image( $attachment_id, $size); ?>
</div>
One of the PartsOne of the Parts
Template Parts haveTemplate Parts have
a hierarchy too!a hierarchy too!
content-book.phpcontent-book.php
content.phcontent.ph
pp
Template Parts haveTemplate Parts have
a hierarchy too!a hierarchy too!
content-book.phpcontent-book.php
content.phcontent.ph
pp
loop.phploop.php
loop-book.phploop-book.php
Don't Get LostDon't Get Lost
in Yourin Your
TemplatesTemplates
Alicia St. RoseAlicia St. Rose
@IntrepidRealist@IntrepidRealist
Review this Session @:
http://wclax.reviews

More Related Content

Viewers also liked (15)

PDF
Angular js, Yeomon & Grunt
Richard Powell
 
PDF
GruntJS + Wordpress
Leonardo Balter
 
PDF
Grunt js and WordPress
WP Australia
 
PDF
Mastering Grunt
Spencer Handley
 
PPT
An Introduction to AngularJs Unittesting
Inthra onsap
 
PPTX
WordPress Theme Development Workflow with Node.js, Ruby, Sass, Bower and Grunt
Brajeshwar Oinam
 
PPTX
Metadata and me
Nick Sheppard
 
PDF
A Quick and Dirty D3.js Tutorial
Young-Ho Kim
 
PDF
Come migliorare le performance di WordPress con il Visual Composer
liciapelliconi.it
 
PDF
Javascript testing: tools of the trade
Juanma Orta
 
PDF
Using Composer to create manageable WordPress websites
Anna Ladoshkina
 
PDF
WordPress Database: What's behind those 12 tables
Mauricio Gelves
 
PDF
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Christopher Bartling
 
PDF
WordPress Template Hierarchy
Sarah Whinnem
 
PDF
Getting Started With Grunt for WordPress Development
David Bisset
 
Angular js, Yeomon & Grunt
Richard Powell
 
GruntJS + Wordpress
Leonardo Balter
 
Grunt js and WordPress
WP Australia
 
Mastering Grunt
Spencer Handley
 
An Introduction to AngularJs Unittesting
Inthra onsap
 
WordPress Theme Development Workflow with Node.js, Ruby, Sass, Bower and Grunt
Brajeshwar Oinam
 
Metadata and me
Nick Sheppard
 
A Quick and Dirty D3.js Tutorial
Young-Ho Kim
 
Come migliorare le performance di WordPress con il Visual Composer
liciapelliconi.it
 
Javascript testing: tools of the trade
Juanma Orta
 
Using Composer to create manageable WordPress websites
Anna Ladoshkina
 
WordPress Database: What's behind those 12 tables
Mauricio Gelves
 
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Christopher Bartling
 
WordPress Template Hierarchy
Sarah Whinnem
 
Getting Started With Grunt for WordPress Development
David Bisset
 

Similar to Wrangling the WordPress Template Hierarchy Like a Boss (20)

PDF
Howdoesgettemplatepartworksintwentytentheme 110123234953-phpapp02
sos informatique
 
PDF
Don’t Panic: How To Troubleshoot Your WordPress Site
WordCamp Sydney
 
PPTX
Exploring the WordPress Dashboard and How to Pick & Install Plugins
Rich Plakas
 
PDF
Wordpress Questions & Answers
Nicole Dion
 
PDF
How does get template part works in twenty ten theme
mohd rozani abd ghani
 
PDF
Theming Wordpress with Adobe
Grace Solivan
 
PPT
WordCamp Detroit 2010 Wordpress Theme Hacks
John Pratt
 
PPTX
Introduction to WordPress
Harshad Mane
 
PPTX
Introduction to WordPress
Harshad Mane
 
PDF
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
LinnAlexandra
 
PPTX
Responsive Theme Workshop - WordCamp Columbus 2015
Joe Querin
 
PDF
Streamlining Your Template Structures When Building Themes
Cameron Jones
 
PPT
Wordpress Beyond A Blog Word Camp Toronto08
Jamie Oastler
 
DOCX
PHP Lesson
Rithirun Meas
 
PPTX
Extending & Scaling | Dallas PHP
randyhoyt
 
PPT
WordPress 2.5 Overview - Rich Media Institute
Brendan Sera-Shriar
 
PDF
A Beginner's Guide to WordPress - WordCamp New York City 2012
Kathryn Presner
 
PPTX
Learning Wordpress - the internal guide
tom altman
 
PPTX
WordPress in 90 minutes
Michelle Castillo
 
PPTX
How to become a word press developer | Wordpress Training in Chandigarh
Cbitss Technologies
 
Howdoesgettemplatepartworksintwentytentheme 110123234953-phpapp02
sos informatique
 
Don’t Panic: How To Troubleshoot Your WordPress Site
WordCamp Sydney
 
Exploring the WordPress Dashboard and How to Pick & Install Plugins
Rich Plakas
 
Wordpress Questions & Answers
Nicole Dion
 
How does get template part works in twenty ten theme
mohd rozani abd ghani
 
Theming Wordpress with Adobe
Grace Solivan
 
WordCamp Detroit 2010 Wordpress Theme Hacks
John Pratt
 
Introduction to WordPress
Harshad Mane
 
Introduction to WordPress
Harshad Mane
 
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
LinnAlexandra
 
Responsive Theme Workshop - WordCamp Columbus 2015
Joe Querin
 
Streamlining Your Template Structures When Building Themes
Cameron Jones
 
Wordpress Beyond A Blog Word Camp Toronto08
Jamie Oastler
 
PHP Lesson
Rithirun Meas
 
Extending & Scaling | Dallas PHP
randyhoyt
 
WordPress 2.5 Overview - Rich Media Institute
Brendan Sera-Shriar
 
A Beginner's Guide to WordPress - WordCamp New York City 2012
Kathryn Presner
 
Learning Wordpress - the internal guide
tom altman
 
WordPress in 90 minutes
Michelle Castillo
 
How to become a word press developer | Wordpress Training in Chandigarh
Cbitss Technologies
 
Ad

Recently uploaded (20)

PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Ad

Wrangling the WordPress Template Hierarchy Like a Boss

Editor's Notes

  • #2: How Many have heard of it?
  • #3: You won&amp;apos;t even see your site if this file isn&amp;apos;t present! Every post, page and custom post type answers to it, unless there are some other staff members taking care of things down the pipeline. The index.php is the ultimate freelancer. Wearing many hats. But, in most themes the hat is pretty much the same. Just a basic loop, so all pages, posts and post types look exactly the same. Boring...
  • #4: How many have heard of it?
  • #5: How many have found this image and gotten more confused after that visit? This wonderfully, interaction resource can found at: http://wphierarchy.com/ But it takes some explainin’ if your not familiar with it. This is going to be my attempt at demystification.
  • #6: In most cases, a theme is made up of many different templates and template parts
  • #8: That work together to create complete pages, posts and attachments that are viewable on the WWW.
  • #9: While, to some, this looks like a foreign mass of confusion, it is readily understood by WordPress. 3. Behind the scenes in the boardroom, WordPress and your theme have teamed up and created naming conventions which they vow to uphold. 4. Because everyone is on the same page, it’s a piece of cake for WordPress to find the right template at the right time.
  • #10: It does this through the magic of Query Power, not Curry Powder, Query Power! We don’t have to go into detail about this super power, the WordPress Codex has ample discussion so your eyes can glaze over later. Just know that WordPress is kindly waiting to deliver on any and all of your template files as long as you’ve named appropriately.
  • #12: You may have noticed this file in your theme. Is the ultimate sole proprietor. Every post, page, archive, comments list, custom post type etc. answers to it. Unless there are other staff members taking care of things down the pipeline, all the content in your site will be delivered a la index.php’s layout.
  • #13: You won&amp;apos;t even see your site if this file isn&amp;apos;t present! Every post, page and custom post type answers to it, unless there are some other staff members taking care of things down the pipeline. The index.php is the ultimate freelancer. Wearing many hats. But, in most themes the hat is pretty much the same. Just a basic loop, so all pages, posts and post types look exactly the same. Boring...
  • #14: In some cases the index.php contains just a basic loop, so all pages, posts, custom post types, everything! look exactly the same. Boring… There are ways to spice up this file, diversify, so to speak: you can fill it with tons of conditional loops depending on what type of page your site is dishing up at the moment. But there’s a better way. Hire some staff, ie, additional, more specific template files, let them take care of some of those loops and layouts.
  • #15: Eventually, you’ll want your index.php to work only part time, maybe even go on an early retirement. Because you’ll have a whole team of templates taking care of the specific tasks that used to wear old index.php out.
  • #16: 1. Let’s start by interviewing some prospects.
  • #17: This is a new position that was created in WordPress 4.3+ When you hire singular.php, her job is to display content on all of your posts, custom post types and pages. She doesn’t do comments, or archives nor God forbid the authors pages. The loops and code you task her with will be displayed the same on your static pages and your blog posts, and those cool custom post types you just made.
  • #20: Looks like we’ve got to hire a couple more temps, ha, templates. Let’s have singular.php delegate her work to page.php and single.php.
  • #21: Of course page.php will handle everything that shows up on the static pages.
  • #24: And single.php? Perhaps you were expecting it to be called post.php? Well, it’s not. single.php is more appropriate because it displays the single page view of a post or custom post type as opposed to it’s archive.
  • #25: As long as we’re mentioning the archive let’s go ahead and add archive.php to the staff. Man is he necessary! archive.php will busy himself dishing out blog posts and custom post types in a list format with featured images and excerpts? Otherwise, index.php was still going to have to handle that.
  • #26: So now we’ve got a pretty solid team! They’re working hard pumping out pages, posts, categories and taxonomy archives. Maybe it’s time for a promotion? More money, less work. Am I right? If you are smart enough to pull that off, you deserve every penny! So Maybe some of the tasks that these temps are doing can be managed by others, more efficiently and more specifically.
  • #27: Let’s look at single.php, for example. Do we really want our blog post and custom post types to look the same. We probably want to ixnay comments on the custom post types, eh?
  • #28: Let’s say our theme is for a popular children and young adult author, Bruce Hale, for example. We have a custom post type for Books. Because he’s written a lot of books! We need a template on staff that is going to work hard to display his individual books in an appealing way, not like a common blog post. Well, we found the right guy for the job: single-book.php
  • #29: He only cares about the single book view. Once he clocks in, he takes the reigns from single.php and diligently works at displaying the unique book layout without unsightlies like comments or post meta .
  • #31: He only cares about the single book view. Once he clocks in, he takes the reigns from single.php and diligently works at displaying the unique book layout without unsightlies like comments or post meta .
  • #32: Of course, since, as mentioned before, Bruce has written a lot of books, we probably want to hire a new temp to take care of the book archive.
  • #33: The perfect qualified candidate showed up: archive-book.php
  • #34: Her job is to focus on the list of all of Bruce’s books and display them in a way more fitting of literature.
  • #35: Now you could get by with this team for just about any theme. And a quick look at the hierarchical chart is a bit easier to grasp.
  • #36: Remember Bruce&amp;apos;s homepage? It has a specific layout that&amp;apos;s different than all of the other static pages. It would be nice if it stayed that way.
  • #37: Specialists that can come in. Don’t have to use them all the time, but they come in handy:
  • #38: front-page.php Like a gate keeper to the homepage of the website.
  • #39: It doesn’t matter what layout template gets turned on in the Admin, front-page.php will not let it slip past. As long as he’s on the staff, that’s what your going to see.
  • #40: home.php can be a bit confusing. You’d think it was the Home Page aka Front Page of the website. It’s not, we’ve already got front-page.php working on that.
  • #41: So what does home.php do? She provides the home to the listing of your blog posts. Once home.php shows up, archive.php can hand off the blog list task to her!
  • #42: Remember way back when I sort of poo poo&amp;apos;d the idea of stuffing a bunch of conditionals into the index.php or any file, for that matter? Well, under the right circumstances, conditionals work quite well! Primarily when dealing with template parts Template parts are files that usually don&amp;apos;t deliver full pages and posts, but rather suppliment or enhance them.
  • #43: The most famous are: header.php which delivers the header on every page of your site
  • #44: sidebar.php which delivers the sidebar to your pages and posts
  • #45: And footer.php which contains the footer info visible on every page of your site. A rule of thumb to follow: The code in full templates can display full page or post on your site. A template part cannot be displayed outside of a post or page. In other, words they don&amp;apos;t stand alone
  • #46: You can create any type of Template part. The can contain loops
  • #47: HTML
  • #48: You can name them anything as long as it&amp;apos;s relevant to and the function of the template part.
  • #49: You can add the template part to anything
  • #50: Back to Bruce&amp;apos;s home page. Remember it had a specific layout on a template called front-page.php?
  • #51: Here&amp;apos;s the simple code of the front-page.php calling the distinctive parts of the page which are in template parts
  • #52: Here&amp;apos;s the template part. Just a div. All content is generated by custom field data.
  • #53: Content-book.php would override simple content.php. Set up a default template part and create additional templates to target more specific posts or post types.
  • #54: Works for any of your template parts..
  • #55: Put comments in files to know where you are. “This is the future home of...”