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. Template
    Hierarchy

    View Slide

  2. View Slide

  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

    View Slide

  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

    View Slide

  5. two different homepages?

    View Slide

  6. Not your normal archive view

    View Slide

  7. Not your normal archive view, again

    View Slide

  8. single-video.php gives us this?

    View Slide

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

    View Slide

  10. i made this!

    View Slide

  11. */
    get_header(); ?>


    ! !


    ! ! ! /**
    ! ! ! * @package wolf_starter
    ! ! ! */
    ! ! ! ?>

    >











    '' . __( 'Pages:', 'wolf_s




    let’s you skip doing conditional
    checks in your template files

    View Slide

  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

    View Slide

  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.

    View Slide

  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.

    View Slide

  15. View Slide

  16. homepage display
    If exists, home.php
    else, index.php

    View Slide

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

    View Slide

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

    View Slide

  19. GIF BREAK

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  25. GIF BREAK #2

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

  32. a pretty standard setup of templates

    View Slide

  33. wpHiearchy.com

    View Slide

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

    View Slide

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

    View Slide