Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Template Hierarchy

Template Hierarchy

Intro to the WordPress Template System.

WordCamp Columbus

Ef0ca9dc51eb3f428e9e6ba89088d51f?s=128

Caleb Burks

July 17, 2015
Tweet

Transcript

  1. TEMPLATE HIERARCHY intro to the WordPress template structure

  2. ABOUT ME ▸ Caleb Burks ▸ WC Ninja at Automattic

    ▸ Loves Gummy Bears ▸ Tweets at @WPprodigy
  3. WHAT'S A TEMPLATE?

  4. None
  5. HOW DOES THE HIERARCHY WORK?

  6. REQUIREMENTS TO BE A THEME ▸ style.css ▸ index.php

  7. STYLE.CSS /* Theme Name: My Theme Theme URI: http://awesometheme.com Author:

    Caleb Burks Author URI: http://author.com Description: Blah Blah License: GNU General Public License v3 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Text Domain: storefront */
  8. MAIN TEMPLATES: INDEX ▸ home.php - blog homepage ▸ index.php

    - backup for home.php
  9. INDEX EXAMPLE

  10. MAIN TEMPLATES: POSTS ▸ single.php - Single Post Page ▸

    singular.php - Fallback (new)
  11. MAIN TEMPLATES: PAGE ▸ front-page.php - static homepage ▸ page.php

    - backup for front-page.php ▸ singular.php - Fallback (new)
  12. AREN'T THERE MORE PARTS?

  13. COMPONENTIZED TEMPLATES ▸ get_header() ▸ get_footer() ▸ get_sidebar()

  14. HEADER.PHP ▸ wp_head() ▸ wp_title() ▸ body_class()

  15. FOOTER.PHP ▸ wp_footer() ▸ date(‘Y’)

  16. SIDEBAR.PHP ▸ dynamic_sidebar()

  17. A CLOSER LOOK

  18. None
  19. INCLUDING TEMPLATES get_template_part(); This is essentially a PHP include or

    require, on steroids.
  20. CONTENT.PHP Used for posts in the index pages. ▸ the_title()

    ▸ the_content() ▸ the_excerpt()
  21. OTHER CONTENT TEMPLATE PARTS content-single.php for single posts. content-page.php for

    single pages. content-search.php for results from searches.
  22. BLOG TEMPLATES ▸ index.php or home.php ▸ content.php

  23. SINGLE TEMPLATES ▸ single.php for single posts ▸ page.php for

    single pages
  24. BUT WAIT, THERE'S MORE!

  25. ARCHIVE TEMPLATES ▸ Categories ▸ Tags ▸ Date-Based ▸ Author-Based

  26. ARCHIVE.PHP Used for displaying archive pages ▸ date.php ▸ category.php

    ▸ taxonomy.php ▸ tag.php ▸ author.php
  27. COMMENTS.PHP ▸ Author comment highlighting ▸ Display gravatars if appropriate

    ▸ Support threaded comments
  28. SEARCH.PHP Displays a list of posts/pages based on search query.

    ▸ Include the search form again ▸ get_search_form()
  29. CUSTOM TEMPLATES

  30. CUSTOM TEMPLATES: ARCHIVES ▸ category-$slug.php ▸ category-$id.php ▸ tag-$slug.php ▸

    tag-$id.php Applies to authors, taxonimies, and CPT's as well.
  31. CUSTOM TEMPLATES: POSTS <?php get_template_part( 'content', get_post_format() ); ?> https://codex.wordpress.org/Post_Formats

    Example: content-video.php
  32. CUSTOM TEMPLATES: PAGES ▸ page-$slug.php ▸ page-$id.php OR...

  33. CUSTOM TEMPLATES: PAGES

  34. CUSTOM TEMPLATES: PAGES Make your own template with just one

    extra line of code!
  35. CUSTOM TEMPLATES: PAGES How to create a custom home page

    template: 1. Copy page.php 2. Rename it to page-home.php 3. Add the following comment to the top: 4. Template Name: Homepage
  36. CONFUSED YET?

  37. AWESOME TOOLS ▸ What The File https://wordpress.org/plugins/what-the- file/

  38. AWESOME TOOLS ▸ WPhierarchy.com

  39. AWESOME TOOLS ▸ _s underscores.com

  40. QUESTIONS?