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

WordCamp Chicago 2013 - Template Hiearchy

WordCamp Chicago 2013 - Template Hiearchy

Brad Parbs

June 28, 2013
Tweet

More Decks by Brad Parbs

Other Decks in Technology

Transcript

  1. 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
  2. “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
  3. */ 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
  4. 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
  5. 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.
  6. 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.
  7. 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