SlideShare a Scribd company logo
WordPress Template Hierarchy
Jason Yingling
Post vs Page vs Webpage
• Webpage – an HTML document being served
to a web browser. The final output of your
PHP into HTML, CSS, and JS.
Post vs Page vs Webpage
• “post” – content stored in the database in the
wp_posts table
Post vs Page vs Webpage
• Post – A default WordPress post of type “Post”
• Page – A default WordPress post of type
“Page”
• Posts, Pages, and Custom Post Types are all
stored together in the wp_posts table of the
database with different types (Post, Page,
Product, etc.)
Template Terminology
• Template Files – PHP files that determine the site’s
markup.
• Page Templates – “those that apply only to pages to
change their look and feel. A page template can be
applied to a single page, a page section, or a class of
pages.”
• Template Tags – Functions used within template files to
retrieve and return data. (ex. the_title() or
the_content()
• Template Hierarchy – The logic WordPress uses to
determine which template file to use to display certain
data
WordPress as a Factory
• posts – The raw materials
• Database – The warehouse
• WordPress theme – The Assembly Line
• The Browser – The consumer
• https://www.youtube.com/watch?v=nR47WZ
GTywE
Crucial Templates
• style.css – determines the theme’s visual
appearance and registers the theme with
WordPress
• functions.php – used for presentational
functionality.
• Template Files – determine the site’s markup.
Uses PHP to convert data from the database
into the HTML output to the browser.
style.css
• (image of registration header)
• Required by WordPress to register the theme
functions.php
• Enqueuing additional stylesheets and scripts
• Creating widgetized areas and menus
Should only be used for presentational functionality
such as:
• Registering Post Types or Custom Taxonomies
• These should go in a plugin so data is not lost when a
theme is switched.
Should not be used for content functionality such as:
Template Files
• Always used files – files used in every template
– header.php
– footer.php
– sidebar.php (if applicable)
• Additional files – files that may or may not be
used depending on content / hierarchy
– index.php
– single.php
– page.php
– And more
Template Partials
• Allows you to easily reuse code throughout
the theme
• header.php, footer.php, and sidebar.php are
some basic examples
• content.php is commonly used to pull in post
content markup
“A template partial is a piece of a template that is included as
part of another template, such as a site header.”
Common Template Files
• index.php – The main template file. Required in all
themes.
• style.css – The main stylesheet. Required in all themes.
• Header.php – Usually contains site’s doc type, meta
info, stylesheets, etc.
• single.php – used when a visitor requests a single post.
• page.php – used when a visitor requests individual
pages
• Many more descriptions available on the Codex -
https://developer.wordpress.org/themes/basics/templ
ate-files/#common-wordpress-template-files
Template Hierarchy
• The logic WordPress uses to determine which
template file to use to return requested post
data
Everything goes back to index.php
• No single.php template? WordPress will use
index.php
• No page.php template? WordPress will use
index.php
https://developer.wordpress.org/files/2014/10/template-hierarchy.png
Single Post
• single-{post-type}-{slug}.php - (since 4.4) – WP looks
for a specific post. Fox example, single-product-
shirt.php would work for a product post type with the
slug shirt.
• single-{post-type}.php – If the post type of the data is
Product, WordPress would look for single-product.php
• single.php – If the above don’t exist, WordPress then
falls back to single.php
• singular.php – If single.php doesn’t exist, WP looks for
singular.php
• index.php - If none of the above exist WordPress falls
back to index.php
Page
• Custom template file – the page template
assigned to the page
• page-{slug}.php – If the page slug is recent-news,
WordPress looks for page-recent-news.php
• page-{id}.php – If the page ID is 6, WordPress
looks for page-6.php
• page.php
• singular.php
• Index.php
Template Hierarchy Resources
• WordPress Codex image -
https://developer.wordpress.org/files/2014/10/t
emplate-hierarchy.png
• Template Hierarchy in Detail -
https://developer.wordpress.org/themes/basics/t
emplate-hierarchy/#the-template-hierarchy-in-
detail
• Interactive Hierarchy map-
http://wphierarchy.com/
• Show Current Template Plugin -
https://wordpress.org/plugins/show-current-
template
WordPress Template hierarchy

More Related Content

What's hot

Castro Chapter 2
Castro Chapter 2Castro Chapter 2
Castro Chapter 2
Jeff Byrnes
 
WordPress as a CMS - Case Study of an Organizational Intranet
WordPress as a CMS - Case Study of an Organizational IntranetWordPress as a CMS - Case Study of an Organizational Intranet
WordPress as a CMS - Case Study of an Organizational Intranet
Tech Liminal
 

What's hot (20)

The WordPress Way
The WordPress WayThe WordPress Way
The WordPress Way
 
WCBos13 intermediate workshop
WCBos13 intermediate workshopWCBos13 intermediate workshop
WCBos13 intermediate workshop
 
Castro Chapter 2
Castro Chapter 2Castro Chapter 2
Castro Chapter 2
 
WP 101 - Local Development - Themes and Plugins
WP 101 - Local Development - Themes and PluginsWP 101 - Local Development - Themes and Plugins
WP 101 - Local Development - Themes and Plugins
 
Wordpress architecture
Wordpress architectureWordpress architecture
Wordpress architecture
 
Keeping Your Themes and Plugins Organized.
Keeping Your Themes and Plugins Organized.Keeping Your Themes and Plugins Organized.
Keeping Your Themes and Plugins Organized.
 
Creating a Reusable Drupal Website for Higher Education - at USG Tech Day
Creating a Reusable Drupal Website for Higher Education - at USG Tech DayCreating a Reusable Drupal Website for Higher Education - at USG Tech Day
Creating a Reusable Drupal Website for Higher Education - at USG Tech Day
 
WP 101 - WordPress Basics
WP 101 - WordPress BasicsWP 101 - WordPress Basics
WP 101 - WordPress Basics
 
WordPress as a CMS
WordPress as a CMSWordPress as a CMS
WordPress as a CMS
 
Creating Landing Pages and Layouts for Drupal 8 - DrupalCon Baltimore
Creating Landing Pages and Layouts for Drupal 8 - DrupalCon BaltimoreCreating Landing Pages and Layouts for Drupal 8 - DrupalCon Baltimore
Creating Landing Pages and Layouts for Drupal 8 - DrupalCon Baltimore
 
WordPress Workshop
WordPress WorkshopWordPress Workshop
WordPress Workshop
 
Visual Design for Content Management Systems
Visual Design for Content Management SystemsVisual Design for Content Management Systems
Visual Design for Content Management Systems
 
WordPress Themes 101 - dotEduGuru Summit 2013
WordPress Themes 101 - dotEduGuru Summit 2013WordPress Themes 101 - dotEduGuru Summit 2013
WordPress Themes 101 - dotEduGuru Summit 2013
 
WordPress as a CMS - Case Study of an Organizational Intranet
WordPress as a CMS - Case Study of an Organizational IntranetWordPress as a CMS - Case Study of an Organizational Intranet
WordPress as a CMS - Case Study of an Organizational Intranet
 
Add Custom Post Types to Your WordPress Website
Add Custom Post Types to Your WordPress WebsiteAdd Custom Post Types to Your WordPress Website
Add Custom Post Types to Your WordPress Website
 
WordPress Themes Demystified
WordPress Themes DemystifiedWordPress Themes Demystified
WordPress Themes Demystified
 
Emkane RCC wp qs
Emkane RCC wp qsEmkane RCC wp qs
Emkane RCC wp qs
 
WordPress as a CMS (short version)
WordPress as a CMS (short version)WordPress as a CMS (short version)
WordPress as a CMS (short version)
 
WordPress Themes 101 - HighEdWeb New England 2013
WordPress Themes 101 - HighEdWeb New England 2013WordPress Themes 101 - HighEdWeb New England 2013
WordPress Themes 101 - HighEdWeb New England 2013
 
Design todevelop
Design todevelopDesign todevelop
Design todevelop
 

Similar to WordPress Template hierarchy

How to get your theme in WordPress
How to get your theme in WordPressHow to get your theme in WordPress
How to get your theme in WordPress
Nisha Singh
 
The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012
Stephanie Leary
 

Similar to WordPress Template hierarchy (20)

Wordpress template hierarchy
Wordpress template hierarchyWordpress template hierarchy
Wordpress template hierarchy
 
Wordpress theme development
Wordpress theme developmentWordpress theme development
Wordpress theme development
 
Intro to WordPress theme development
Intro to WordPress theme developmentIntro to WordPress theme development
Intro to WordPress theme development
 
Content-Driven WordPress Development - WordCamp Omaha 2014
Content-Driven WordPress Development - WordCamp Omaha 2014Content-Driven WordPress Development - WordCamp Omaha 2014
Content-Driven WordPress Development - WordCamp Omaha 2014
 
Basic word press development
Basic word press developmentBasic word press development
Basic word press development
 
WordPress Theme Workshop: Part 2
WordPress Theme Workshop: Part 2WordPress Theme Workshop: Part 2
WordPress Theme Workshop: Part 2
 
The Flexibility of WordPress
The Flexibility of WordPressThe Flexibility of WordPress
The Flexibility of WordPress
 
How to get your theme in WordPress
How to get your theme in WordPressHow to get your theme in WordPress
How to get your theme in WordPress
 
MCC Web Design Workshop
MCC Web Design WorkshopMCC Web Design Workshop
MCC Web Design Workshop
 
The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012
 
Newbies guide to customizing word press themes 25
Newbies guide to customizing word press themes 25Newbies guide to customizing word press themes 25
Newbies guide to customizing word press themes 25
 
Starting WordPress Theme Review
Starting WordPress Theme ReviewStarting WordPress Theme Review
Starting WordPress Theme Review
 
WordPress Theming 101
WordPress Theming 101WordPress Theming 101
WordPress Theming 101
 
MVC Web Application
MVC Web ApplicationMVC Web Application
MVC Web Application
 
Anatomy of a Wordpress theme
Anatomy of a Wordpress themeAnatomy of a Wordpress theme
Anatomy of a Wordpress theme
 
Builing a WordPress Theme
Builing a WordPress ThemeBuiling a WordPress Theme
Builing a WordPress Theme
 
Arizona WP - Building a WordPress Theme
Arizona WP - Building a WordPress ThemeArizona WP - Building a WordPress Theme
Arizona WP - Building a WordPress Theme
 
itPage LDC 09 Presentation
itPage LDC 09 PresentationitPage LDC 09 Presentation
itPage LDC 09 Presentation
 
Websites With Wordpress
Websites With WordpressWebsites With Wordpress
Websites With Wordpress
 
Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Writing a WordPress Theme - HighEdWeb 2013 #WRK2Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Writing a WordPress Theme - HighEdWeb 2013 #WRK2
 

More from Jason Yingling

More from Jason Yingling (13)

WordPress Security Best Practices
WordPress Security Best PracticesWordPress Security Best Practices
WordPress Security Best Practices
 
Installing WP-CLI locally
Installing WP-CLI locallyInstalling WP-CLI locally
Installing WP-CLI locally
 
Getting Started with Gutenberg Development
Getting Started with Gutenberg DevelopmentGetting Started with Gutenberg Development
Getting Started with Gutenberg Development
 
Plugin development
Plugin developmentPlugin development
Plugin development
 
Introducing CSS Grid
Introducing CSS GridIntroducing CSS Grid
Introducing CSS Grid
 
Customizing the WordPress Customizer
Customizing the WordPress CustomizerCustomizing the WordPress Customizer
Customizing the WordPress Customizer
 
Battling Google PageSpeed Insights
Battling Google PageSpeed InsightsBattling Google PageSpeed Insights
Battling Google PageSpeed Insights
 
Putting the Develop in Development
Putting the Develop in Development Putting the Develop in Development
Putting the Develop in Development
 
Getting to Know Underscores
Getting to Know Underscores Getting to Know Underscores
Getting to Know Underscores
 
Speeding Up WordPress sites
Speeding Up WordPress sitesSpeeding Up WordPress sites
Speeding Up WordPress sites
 
Creating Dynamic Sidebars & Widgets in WordPress
Creating Dynamic Sidebars & Widgets in WordPressCreating Dynamic Sidebars & Widgets in WordPress
Creating Dynamic Sidebars & Widgets in WordPress
 
Ithemes presentation
Ithemes presentationIthemes presentation
Ithemes presentation
 
Building Flexible Sites with Advanced Custom Fields
Building Flexible Sites with Advanced Custom FieldsBuilding Flexible Sites with Advanced Custom Fields
Building Flexible Sites with Advanced Custom Fields
 

Recently uploaded

一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
aagad
 
Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
abhinandnam9997
 
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkkaudience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
lolsDocherty
 

Recently uploaded (13)

The AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdfThe AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdf
 
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
 
How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 
The Best AI Powered Software - Intellivid AI Studio
The Best AI Powered Software - Intellivid AI StudioThe Best AI Powered Software - Intellivid AI Studio
The Best AI Powered Software - Intellivid AI Studio
 
Bug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's GuideBug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's Guide
 
The Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyThe Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case Study
 
Case study on merger of Vodafone and Idea (VI).pptx
Case study on merger of Vodafone and Idea (VI).pptxCase study on merger of Vodafone and Idea (VI).pptx
Case study on merger of Vodafone and Idea (VI).pptx
 
ER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAE
 
Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
Pvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdf
 
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkkaudience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
 

WordPress Template hierarchy

  • 2. Post vs Page vs Webpage • Webpage – an HTML document being served to a web browser. The final output of your PHP into HTML, CSS, and JS.
  • 3. Post vs Page vs Webpage • “post” – content stored in the database in the wp_posts table
  • 4. Post vs Page vs Webpage • Post – A default WordPress post of type “Post” • Page – A default WordPress post of type “Page” • Posts, Pages, and Custom Post Types are all stored together in the wp_posts table of the database with different types (Post, Page, Product, etc.)
  • 5. Template Terminology • Template Files – PHP files that determine the site’s markup. • Page Templates – “those that apply only to pages to change their look and feel. A page template can be applied to a single page, a page section, or a class of pages.” • Template Tags – Functions used within template files to retrieve and return data. (ex. the_title() or the_content() • Template Hierarchy – The logic WordPress uses to determine which template file to use to display certain data
  • 6. WordPress as a Factory • posts – The raw materials • Database – The warehouse • WordPress theme – The Assembly Line • The Browser – The consumer • https://www.youtube.com/watch?v=nR47WZ GTywE
  • 7. Crucial Templates • style.css – determines the theme’s visual appearance and registers the theme with WordPress • functions.php – used for presentational functionality. • Template Files – determine the site’s markup. Uses PHP to convert data from the database into the HTML output to the browser.
  • 8. style.css • (image of registration header) • Required by WordPress to register the theme
  • 9. functions.php • Enqueuing additional stylesheets and scripts • Creating widgetized areas and menus Should only be used for presentational functionality such as: • Registering Post Types or Custom Taxonomies • These should go in a plugin so data is not lost when a theme is switched. Should not be used for content functionality such as:
  • 10. Template Files • Always used files – files used in every template – header.php – footer.php – sidebar.php (if applicable) • Additional files – files that may or may not be used depending on content / hierarchy – index.php – single.php – page.php – And more
  • 11. Template Partials • Allows you to easily reuse code throughout the theme • header.php, footer.php, and sidebar.php are some basic examples • content.php is commonly used to pull in post content markup “A template partial is a piece of a template that is included as part of another template, such as a site header.”
  • 12. Common Template Files • index.php – The main template file. Required in all themes. • style.css – The main stylesheet. Required in all themes. • Header.php – Usually contains site’s doc type, meta info, stylesheets, etc. • single.php – used when a visitor requests a single post. • page.php – used when a visitor requests individual pages • Many more descriptions available on the Codex - https://developer.wordpress.org/themes/basics/templ ate-files/#common-wordpress-template-files
  • 13. Template Hierarchy • The logic WordPress uses to determine which template file to use to return requested post data
  • 14. Everything goes back to index.php • No single.php template? WordPress will use index.php • No page.php template? WordPress will use index.php
  • 16.
  • 17. Single Post • single-{post-type}-{slug}.php - (since 4.4) – WP looks for a specific post. Fox example, single-product- shirt.php would work for a product post type with the slug shirt. • single-{post-type}.php – If the post type of the data is Product, WordPress would look for single-product.php • single.php – If the above don’t exist, WordPress then falls back to single.php • singular.php – If single.php doesn’t exist, WP looks for singular.php • index.php - If none of the above exist WordPress falls back to index.php
  • 18. Page • Custom template file – the page template assigned to the page • page-{slug}.php – If the page slug is recent-news, WordPress looks for page-recent-news.php • page-{id}.php – If the page ID is 6, WordPress looks for page-6.php • page.php • singular.php • Index.php
  • 19. Template Hierarchy Resources • WordPress Codex image - https://developer.wordpress.org/files/2014/10/t emplate-hierarchy.png • Template Hierarchy in Detail - https://developer.wordpress.org/themes/basics/t emplate-hierarchy/#the-template-hierarchy-in- detail • Interactive Hierarchy map- http://wphierarchy.com/ • Show Current Template Plugin - https://wordpress.org/plugins/show-current- template