SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Towards an Alternate Theme
Structure?
Graham Armfield
Web Accessibility Consultant
WordPress Developer

graham.armfield@coolfields.co.uk
@coolfields

Coolfields Consulting

www.coolfields.co.uk
@coolfields
What I’m going to cover
An idea to make it easier to reuse themes for
another project, and potentially to allow for
easier child theming.
• It’s just an idea
• Might be useful
• Looking for feedback

2
Perils of child theming - structure
archive.php and category.php
<section id="primary" class="site-content">
<div id="content" role="main">
<?php if ( have_posts() ) : ?>
…

index.php and page.php
<div id="primary" class="site-content">
<div id="content" role="main">
<?php if ( have_posts() ) : ?>
…

Structural HTML
3
A typical page structure
Banner
Navigation
Content

Sidebar

Footer
4
In simple HTML
<html>
<head> Meta tags, CSS, scripts </head>
<body>
<div id=”banner”> Logos etc </div>
<div id=”navigation”> Navigation </div>
<div id=”content”> Content </div>
<div id=”sidebar”> Widgets etc</div>
<div id=”footer”> Footer </div>
</body>
</html>

5
Introducing layout.php
<html>
<?php get_header(); ?>
<body>
<div id=”banner”>
<?php get_template_part( 'banner' );?>
</div>
<div id=”navigation”>
<?php get_template_part( ‘navigation' );?>
</div>
<div id=”content”>
<?php get_template_part( ‘content' );?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
</body>
</html>
6
index.php
<?php get_template_part( ‘layout' );?>

7
Other changes
header.php
• Just meta tags, scripts and CSS
• Still need wp_head()

banner.php
• Just the code/function required for the banner

navigation.php
• Just the code/functions required for navigation

Etc
8
content.php
<? php if (have_posts()) : while
(have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
Note: no structural HTML
9
Different types of content
In layout.php
if (is_front_page()) {
get_template_part( 'content','front' );
} elseif(is_home()) {
get_template_part( 'content','bloglist' );
} elseif(is_single()) {
get_template_part( 'content','single' );
} else {
get_template_part( 'content' );
}

10
Different types of content
Then you could have separate files –
• content.php – for pages
• content-front.php – for the front page
• content-bloglist.php – for blog index
• content-single.php – for individual blog posts

11
Advantages
• Structure of theme template only described once –
layout.php
• To change the layout of the theme, just change layout.php
• Each file is completely self-contained – no starting a div in
the header.php and ending it in the footer.php
• A new child theme may only need a new banner.php and a
style.css – all the other files could be the same

12
Things to watch for
Scope of variables
• Problem: variable set in layout.php not readily available in
banner.php, content.php, etc
• Solution: create setter and getter functions for variables

13
Also can work with:
Custom page templates
1) set template name in template file
setTemplateName(‘mytemplate’);
get_template_part(‘layout’);

2) test on template name in layout.php
get_template_part('content', getTemplateName());

Custom post types
get_template_part('content', get_post_format());
14
Thanks for listening
please let me know what you think
graham.armfield@coolfields.co.uk
@coolfields

15

Weitere ähnliche Inhalte

Was ist angesagt?

Word press templates
Word press templatesWord press templates
Word press templates
Dan Phiffer
 

Was ist angesagt? (20)

WordPress Theme Structure
WordPress Theme StructureWordPress Theme Structure
WordPress Theme Structure
 
Minimalist Theming: How to Build a Lean, Mean Drupal 8 Theme
Minimalist Theming: How to Build a Lean, Mean Drupal 8 ThemeMinimalist Theming: How to Build a Lean, Mean Drupal 8 Theme
Minimalist Theming: How to Build a Lean, Mean Drupal 8 Theme
 
Web1O1 - Intro to HTML/CSS
Web1O1 - Intro to HTML/CSSWeb1O1 - Intro to HTML/CSS
Web1O1 - Intro to HTML/CSS
 
A Custom Drupal Theme in 40 Minutes
A Custom Drupal Theme in 40 MinutesA Custom Drupal Theme in 40 Minutes
A Custom Drupal Theme in 40 Minutes
 
Word press templates
Word press templatesWord press templates
Word press templates
 
Introduction to WordPress Theme Development
Introduction to WordPress Theme DevelopmentIntroduction to WordPress Theme Development
Introduction to WordPress Theme Development
 
Wordpress theme framework : Roots
Wordpress theme framework : RootsWordpress theme framework : Roots
Wordpress theme framework : Roots
 
Meetup child-themes
Meetup child-themesMeetup child-themes
Meetup child-themes
 
Customizing WordPress Themes
Customizing WordPress ThemesCustomizing WordPress Themes
Customizing WordPress Themes
 
Custom Menu Support for WordPress Themes
Custom Menu Support for WordPress ThemesCustom Menu Support for WordPress Themes
Custom Menu Support for WordPress Themes
 
Converting (X)HTML/CSS template to Drupal 7 Theme
Converting (X)HTML/CSS template to Drupal 7 ThemeConverting (X)HTML/CSS template to Drupal 7 Theme
Converting (X)HTML/CSS template to Drupal 7 Theme
 
Launching a WordPress Site 101 (Cincinnati WordPress, August 2015)
Launching a WordPress Site 101 (Cincinnati WordPress, August 2015)Launching a WordPress Site 101 (Cincinnati WordPress, August 2015)
Launching a WordPress Site 101 (Cincinnati WordPress, August 2015)
 
Developing Your Ultimate Package
Developing Your Ultimate PackageDeveloping Your Ultimate Package
Developing Your Ultimate Package
 
Wordpress template hierarchy
Wordpress template hierarchyWordpress template hierarchy
Wordpress template hierarchy
 
WordPress Themes and Plugins
WordPress Themes and PluginsWordPress Themes and Plugins
WordPress Themes and Plugins
 
Becoming a Respected WordPress Developer
Becoming a Respected WordPress DeveloperBecoming a Respected WordPress Developer
Becoming a Respected WordPress Developer
 
Building themesfromscratchwithframeworks
Building themesfromscratchwithframeworksBuilding themesfromscratchwithframeworks
Building themesfromscratchwithframeworks
 
WordPress Theme Development
WordPress Theme DevelopmentWordPress Theme Development
WordPress Theme Development
 
How to Prepare a WordPress Theme for Public Release
How to Prepare a WordPress Theme for Public ReleaseHow to Prepare a WordPress Theme for Public Release
How to Prepare a WordPress Theme for Public Release
 
WordPress Template Hierarchy
WordPress Template HierarchyWordPress Template Hierarchy
WordPress Template Hierarchy
 

Andere mochten auch

Presenting technology research
Presenting technology researchPresenting technology research
Presenting technology research
courcunn
 

Andere mochten auch (9)

Assistive Technology Demo Londonweb
Assistive Technology Demo LondonwebAssistive Technology Demo Londonweb
Assistive Technology Demo Londonweb
 
Handling User Generated Content in WordPress
Handling User Generated Content in WordPressHandling User Generated Content in WordPress
Handling User Generated Content in WordPress
 
Themes, Plugins and Accessibility
Themes, Plugins and AccessibilityThemes, Plugins and Accessibility
Themes, Plugins and Accessibility
 
Web Accessibility: What it is, Why it's important
Web Accessibility: What it is, Why it's importantWeb Accessibility: What it is, Why it's important
Web Accessibility: What it is, Why it's important
 
So What is This Thing Called WordPress?
So What is This Thing Called WordPress?So What is This Thing Called WordPress?
So What is This Thing Called WordPress?
 
Wordpress and Web Accessibility Wordcamp UK 2014
Wordpress and Web Accessibility Wordcamp UK 2014Wordpress and Web Accessibility Wordcamp UK 2014
Wordpress and Web Accessibility Wordcamp UK 2014
 
Presenting technology research
Presenting technology researchPresenting technology research
Presenting technology research
 
WordPress Theme Unit Tests
WordPress Theme Unit TestsWordPress Theme Unit Tests
WordPress Theme Unit Tests
 
So How Do I Know if My Website is Accessible?
So How Do I Know if My Website is Accessible?So How Do I Know if My Website is Accessible?
So How Do I Know if My Website is Accessible?
 

Ähnlich wie Towards an Alternate WordPress Theme Structure

Meetup child-themes
Meetup child-themesMeetup child-themes
Meetup child-themes
DaisyOlsen
 
Meetup child-themes
Meetup child-themesMeetup child-themes
Meetup child-themes
DaisyOlsen
 

Ähnlich wie Towards an Alternate WordPress Theme Structure (20)

Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
 
Overview on WordPress theme file structure and working functionality
Overview on WordPress theme file structure and working functionality Overview on WordPress theme file structure and working functionality
Overview on WordPress theme file structure and working functionality
 
Child Themes (WordCamp Dublin 2017) with notes
Child Themes (WordCamp Dublin 2017) with notesChild Themes (WordCamp Dublin 2017) with notes
Child Themes (WordCamp Dublin 2017) with notes
 
Crash Course in Theme Surgery
Crash Course in Theme SurgeryCrash Course in Theme Surgery
Crash Course in Theme Surgery
 
Arizona WP - Building a WordPress Theme
Arizona WP - Building a WordPress ThemeArizona WP - Building a WordPress Theme
Arizona WP - Building a WordPress Theme
 
Builing a WordPress Theme
Builing a WordPress ThemeBuiling a WordPress Theme
Builing a WordPress Theme
 
Anatomy of a Wordpress theme
Anatomy of a Wordpress themeAnatomy of a Wordpress theme
Anatomy of a Wordpress theme
 
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
 
Adopt or hack - how to hack a theme in a Drupal way
Adopt or hack - how to hack a theme in a Drupal wayAdopt or hack - how to hack a theme in a Drupal way
Adopt or hack - how to hack a theme in a Drupal way
 
Introduction to-concrete-5
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5
 
Introduction to-concrete-5
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5
 
Drupal theming
Drupal themingDrupal theming
Drupal theming
 
Intro to WordPress Child Themes (NERDS Sept 2014)
Intro to WordPress Child Themes (NERDS Sept 2014)Intro to WordPress Child Themes (NERDS Sept 2014)
Intro to WordPress Child Themes (NERDS Sept 2014)
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017
 
Firstborn child theme word camp presentation - atlanta 2013
Firstborn child theme   word camp presentation - atlanta 2013Firstborn child theme   word camp presentation - atlanta 2013
Firstborn child theme word camp presentation - atlanta 2013
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme Enlightenment
 
Meetup child-themes
Meetup child-themesMeetup child-themes
Meetup child-themes
 
Meetup child-themes
Meetup child-themesMeetup child-themes
Meetup child-themes
 
Theme Kickstart
Theme KickstartTheme Kickstart
Theme Kickstart
 
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
 

Mehr von Graham Armfield

Mehr von Graham Armfield (20)

Useful Accessibility Tools Version 3 - Jul 2021
Useful Accessibility Tools Version 3 - Jul 2021Useful Accessibility Tools Version 3 - Jul 2021
Useful Accessibility Tools Version 3 - Jul 2021
 
So how do i know if my wordpress website is accessible - WordPress Accessibil...
So how do i know if my wordpress website is accessible - WordPress Accessibil...So how do i know if my wordpress website is accessible - WordPress Accessibil...
So how do i know if my wordpress website is accessible - WordPress Accessibil...
 
Useful Accessibility Tools - WordCamp Brighton
Useful Accessibility Tools - WordCamp BrightonUseful Accessibility Tools - WordCamp Brighton
Useful Accessibility Tools - WordCamp Brighton
 
Accessibility Hacks Version 2
Accessibility Hacks Version 2Accessibility Hacks Version 2
Accessibility Hacks Version 2
 
Accessibility Hacks version 2
Accessibility Hacks version 2Accessibility Hacks version 2
Accessibility Hacks version 2
 
Useful Accessibility Tools - WP Pompey April 2019
Useful Accessibility Tools - WP Pompey April 2019Useful Accessibility Tools - WP Pompey April 2019
Useful Accessibility Tools - WP Pompey April 2019
 
How to Build an Accessible WordPress Theme
How to Build an Accessible WordPress ThemeHow to Build an Accessible WordPress Theme
How to Build an Accessible WordPress Theme
 
Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018
 
Useful Accessibility Tools
Useful Accessibility ToolsUseful Accessibility Tools
Useful Accessibility Tools
 
Assistive technology Demo WordCamp Bristol
Assistive technology Demo WordCamp BristolAssistive technology Demo WordCamp Bristol
Assistive technology Demo WordCamp Bristol
 
Designing for Accessibility - WordCamp London 2017
Designing for Accessibility - WordCamp London 2017Designing for Accessibility - WordCamp London 2017
Designing for Accessibility - WordCamp London 2017
 
Designing for Accessibility - Front End North - September 2016
Designing for Accessibility - Front End North - September 2016Designing for Accessibility - Front End North - September 2016
Designing for Accessibility - Front End North - September 2016
 
Obscure Wordpress Functions That Are Actually Quite Useful
Obscure Wordpress Functions That Are Actually Quite UsefulObscure Wordpress Functions That Are Actually Quite Useful
Obscure Wordpress Functions That Are Actually Quite Useful
 
Themes Plugins and Accessibility - WordCamp London March 2015
Themes Plugins and Accessibility - WordCamp London March 2015Themes Plugins and Accessibility - WordCamp London March 2015
Themes Plugins and Accessibility - WordCamp London March 2015
 
Can WordPress help make the web more accessible - eaccess15 - Feb 2015
Can WordPress help make the web more accessible - eaccess15 - Feb 2015Can WordPress help make the web more accessible - eaccess15 - Feb 2015
Can WordPress help make the web more accessible - eaccess15 - Feb 2015
 
So, How Do I Know if my WordPress Website is Accessible?
So, How Do I Know if my WordPress Website is Accessible?So, How Do I Know if my WordPress Website is Accessible?
So, How Do I Know if my WordPress Website is Accessible?
 
WordPress and Web Accessibility - 2013
WordPress and Web Accessibility - 2013WordPress and Web Accessibility - 2013
WordPress and Web Accessibility - 2013
 
Beginners Guide To Web Accessibility - WordCamp UK July 2013
Beginners Guide To Web Accessibility - WordCamp UK July 2013Beginners Guide To Web Accessibility - WordCamp UK July 2013
Beginners Guide To Web Accessibility - WordCamp UK July 2013
 
Simple Usability Tweaks for Your WordPress Theme
Simple Usability Tweaks for Your WordPress ThemeSimple Usability Tweaks for Your WordPress Theme
Simple Usability Tweaks for Your WordPress Theme
 
WordPress and Web Accessibility - TCUK 2012
WordPress and Web Accessibility - TCUK 2012WordPress and Web Accessibility - TCUK 2012
WordPress and Web Accessibility - TCUK 2012
 

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Kürzlich hochgeladen (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Towards an Alternate WordPress Theme Structure

  • 1. Towards an Alternate Theme Structure? Graham Armfield Web Accessibility Consultant WordPress Developer graham.armfield@coolfields.co.uk @coolfields Coolfields Consulting www.coolfields.co.uk @coolfields
  • 2. What I’m going to cover An idea to make it easier to reuse themes for another project, and potentially to allow for easier child theming. • It’s just an idea • Might be useful • Looking for feedback 2
  • 3. Perils of child theming - structure archive.php and category.php <section id="primary" class="site-content"> <div id="content" role="main"> <?php if ( have_posts() ) : ?> … index.php and page.php <div id="primary" class="site-content"> <div id="content" role="main"> <?php if ( have_posts() ) : ?> … Structural HTML 3
  • 4. A typical page structure Banner Navigation Content Sidebar Footer 4
  • 5. In simple HTML <html> <head> Meta tags, CSS, scripts </head> <body> <div id=”banner”> Logos etc </div> <div id=”navigation”> Navigation </div> <div id=”content”> Content </div> <div id=”sidebar”> Widgets etc</div> <div id=”footer”> Footer </div> </body> </html> 5
  • 6. Introducing layout.php <html> <?php get_header(); ?> <body> <div id=”banner”> <?php get_template_part( 'banner' );?> </div> <div id=”navigation”> <?php get_template_part( ‘navigation' );?> </div> <div id=”content”> <?php get_template_part( ‘content' );?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?> </body> </html> 6
  • 8. Other changes header.php • Just meta tags, scripts and CSS • Still need wp_head() banner.php • Just the code/function required for the banner navigation.php • Just the code/functions required for navigation Etc 8
  • 9. content.php <? php if (have_posts()) : while (have_posts()) : the_post(); ?> <h1><?php the_title(); ?></h1> <?php the_content(); ?> <?php endwhile; ?> <?php else : ?> <h2>Not Found</h2> <?php endif; ?> Note: no structural HTML 9
  • 10. Different types of content In layout.php if (is_front_page()) { get_template_part( 'content','front' ); } elseif(is_home()) { get_template_part( 'content','bloglist' ); } elseif(is_single()) { get_template_part( 'content','single' ); } else { get_template_part( 'content' ); } 10
  • 11. Different types of content Then you could have separate files – • content.php – for pages • content-front.php – for the front page • content-bloglist.php – for blog index • content-single.php – for individual blog posts 11
  • 12. Advantages • Structure of theme template only described once – layout.php • To change the layout of the theme, just change layout.php • Each file is completely self-contained – no starting a div in the header.php and ending it in the footer.php • A new child theme may only need a new banner.php and a style.css – all the other files could be the same 12
  • 13. Things to watch for Scope of variables • Problem: variable set in layout.php not readily available in banner.php, content.php, etc • Solution: create setter and getter functions for variables 13
  • 14. Also can work with: Custom page templates 1) set template name in template file setTemplateName(‘mytemplate’); get_template_part(‘layout’); 2) test on template name in layout.php get_template_part('content', getTemplateName()); Custom post types get_template_part('content', get_post_format()); 14
  • 15. Thanks for listening please let me know what you think graham.armfield@coolfields.co.uk @coolfields 15