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

WordCamp Chicago 2013 - Template Hiearchy

WordCamp Chicago 2013 - Template Hiearchy

D529f2403e21f08bfa16365bdf032f81?s=128

Brad Parbs

June 28, 2013
Tweet

Transcript

  1. Template Hierarchy

  2. None
  3. I’m Brad Parbs. Created Wolf, hook_s & wpWizard Core Contributor

    in 3.5 & 3.6 Run Snow Day Group, (snowday.io) ♥ WordPress, Startups, and Code Plugin and Theme author/developer @BradParbs brad.parbs.me Powered by Chai Tea
  4. “WordPress Templates fit together like the pieces of a puzzle

    to generate the web pages on your WordPress site. Some templates (the header and footer template files for example) are used on all the web pages, while others are used only under specific conditions.” what the heck is this about? - da codex
  5. two different homepages?

  6. Not your normal archive view

  7. Not your normal archive view, again

  8. single-video.php gives us this?

  9. why is this important? because This is easier to manage

    than this
  10. i made this!

  11. */ get_header(); ?> <div id="primary"> <div id="content" role="main"> ! !

    <?php if ( have_posts() ) : ?> <?php /* Start the Loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php ! ! ! /** ! ! ! * @package wolf_starter ! ! ! */ ! ! ! ?> <?php tha_entry_before(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <?php tha_entry_top(); ?> <header class="entry-header"> <?php if( is_front_page() || is_home() ){ ?> <h1 class="entry-title"><?php the_title(); ?></h1> <?php } ?> <div class="entry-meta"> <?php wolf_starter_posted_on(); ?> </div><!-- .entry-meta --> </header><!-- .entry-header --> <div class="entry-content"> <?php the_content(); ?> <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'wolf_s </div><!-- .entry-content --> <?php tha_entry_bottom(); ?> </article><!-- #post-## --> <?php tha_entry_after(); ?> let’s you skip doing conditional checks in your template files
  12. how it works WordPress uses the Query String — information

    contained within each link on your web site — to decide which template or set of templates will be used to display the page. First, WordPress matches every Query String to query types — i.e. it decides what type of page (a search page, a category page, the home page etc.) is being requested. Templates are then chosen — and web page content is generated — in the order suggested by the WordPress Template hierarchy, depending upon what templates are available in a particular WordPress Theme. WordPress looks for template files with specific names in the current Theme's directory and uses the first matching template file listed under the appropriate query section below. With the exception of the basic index.php template file, Theme developers can choose whether they want to implement a particular template file or not. If WordPress cannot find a template file with a matching name, it skips down to the next file name in the hierarchy. If WordPress cannot find any matching template file, index.php (the Theme's home page template file) will be used. 1.Checks the url 2. Figures out what you’re doing 3. Picks a template to load up 4. Using specific names in order 5. Defaults to known names, then index.php
  13. example: Category archive view http://example.com/category/your-category/ 1. If the category's ID

    is 4, WordPress looks for a template file named category-4.php. 2. If it is missing, WordPress next looks for a generic category template file, category.php 3. If this file does not exist either, WordPress looks for a generic archive template, archive.php. 4. If it is missing as well, WordPress falls back on the main Theme template file, index.php.
  14. example: homepage http://example.com/ 1. WordPress first determines whether it has

    a static front page. 2. If a static front page has not been set, then WordPress looks for a template file called home.php and uses it to generate the requested page. 3. If home.php is missing, WordPress looks for a file called index.php in the active theme's directory, and uses that template to generate the page.
  15. None
  16. homepage display If exists, home.php else, index.php

  17. front page display If exists, front-page.php else, Settings->Reading

  18. single post display If exists, single-{post-type}.php else, single.php else, index.php

  19. GIF BREAK

  20. page display If exists, Custom Page Template else, page-{slug}.php else,

    page-{id}.php else, page.php else, index.php
  21. category display If exists, category-{slug}.php else, category-{id}.php else, category.php else,

    archive.php else, index.php
  22. tag display If exists, tag-{slug}.php else, tag-{id}.php else, tag.php else,

    archive.php else, index.php
  23. custom taxonomies If exists, taxonomy-{taxonomy}-{term}.php else, taxonomy-{taxonomy}.php else, taxonomy.php else,

    archive.php else, index.php
  24. custom post types archive display (yeeeeaa If exists, archive-{post-type-name}.php else,

    archive.php else, index.php
  25. GIF BREAK #2

  26. author display If exists, author-{nicename}.php else, author-{id}.php else, author.php else,

    archive.php else, index.php
  27. date display If exists, date.php else, archive.php else, index.php

  28. search results If exists, search.php else, index.php

  29. attachments If exists, MIME_TYPE.php like: video.php image.php pdf.php text.php else,

    attachment.php else, single-attachment.php else, single.php else, index.php
  30. 404 no results page If exists, 404.php else, index.php

  31. reminders Generally, it goes first {slug}, then {id}, then something,

    finally, index.php
  32. a pretty standard setup of templates

  33. wpHiearchy.com

  34. codes and stuff wp-includes/template-loader.php line 25

  35. codes and stuff wp-includes/template-loader.php line 25