Templating WordPress
Konstantin Kovshenin
Automattic
author-$nicename.php
author-$id.php
author.php
archive.php
paged.php
index.php
$templates = array(
'foo.php',
'bar.php',
'baz.php',
);
$template = locate_template( $templates );
function get_sidebar( $name = null ) {
$templates = array();
if ( '' !== $name )
$templates[] = "sidebar-{$name}.php";
$te...
get_sidebar( 'left' );
// sidebar-left.php
// sidebar.php
get_header( 'foo' );
// header-foo.php
// header.php
get_footer( 'bar' );
// footer-bar.php
// footer.php
get_template_part( 'foo', 'bar' );
// foo-bar.php
// foo.php
get_template_part( 'content',
get_post_format() );
//
//
//
//
//

content-gallery.php
content-quote.php
content-image.php...
template-loader.php
if

( is_404()

&& $template = get_404_template()

) :

	 elseif ( is_tag()

&& $template = get_tag_template()

) :

	 els...
if

( is_404()

&& $template = get_404_template()

) :

	 elseif ( is_tag()

&& $template = get_tag_template()

) :

	 els...
if

( is_404()

&& $template = get_404_template()

) :

	 elseif ( is_tag()

&& $template = get_tag_template()

) :

	 els...
if

( is_404()

&& $template = get_404_template()

) :

	 elseif ( is_tag()

&& $template = get_tag_template()

) :

	 els...
// get_author_template()
$templates[] = "author-{$author->nicename}.php";
$templates[] = "author-{$author->ID}.php";
$temp...
if

( is_404()

&& $template = get_404_template()

) :

	 elseif ( is_tag()

&& $template = get_tag_template()

) :

	 els...
if ( $template = apply_filters(
'template_include', $template ) )
include( $template );
function my_template_include( $template ) {
if ( my_is_maintenance() &&
$located = locate_template( 'maintenance.php' ) )
...
locate_template( array(
'foo.php', 'bar.php', 'baz.php' ) );
//
//
//
//
//
//

child/foo.php
parent/foo.php
child/bar.php...
locate_template( 'related-posts.php', true );
// child/related-posts.php
// parent/related-posts.php
// vs: require get_te...
wp-includes/template-loader.php
wp-includes/general-template.php
wp-includes/template.php
kovshenin.com/wcsof2013
Templating WordPress
Templating WordPress
Templating WordPress
Templating WordPress
Upcoming SlideShare
Loading in …5
×

Templating WordPress

5,761 views
5,636 views

Published on

At WordCamp Sofia 2013

Published in: Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,761
On SlideShare
0
From Embeds
0
Number of Embeds
530
Actions
Shares
0
Downloads
16
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Templating WordPress

  1. 1. Templating WordPress Konstantin Kovshenin Automattic
  2. 2. author-$nicename.php author-$id.php author.php archive.php paged.php index.php
  3. 3. $templates = array( 'foo.php', 'bar.php', 'baz.php', ); $template = locate_template( $templates );
  4. 4. function get_sidebar( $name = null ) { $templates = array(); if ( '' !== $name ) $templates[] = "sidebar-{$name}.php"; $templates[] = 'sidebar.php'; } locate_template( $templates, true );
  5. 5. get_sidebar( 'left' ); // sidebar-left.php // sidebar.php
  6. 6. get_header( 'foo' ); // header-foo.php // header.php get_footer( 'bar' ); // footer-bar.php // footer.php
  7. 7. get_template_part( 'foo', 'bar' ); // foo-bar.php // foo.php
  8. 8. get_template_part( 'content', get_post_format() ); // // // // // content-gallery.php content-quote.php content-image.php ... content.php
  9. 9. template-loader.php
  10. 10. if ( is_404() && $template = get_404_template() ) : elseif ( is_tag() && $template = get_tag_template() ) : elseif ( is_date() && $template = get_date_template() ) : elseif ( is_category() && $template = get_category_template() ) : elseif ( is_author() elseif ( is_archive() elseif ( is_paged() else : && $template = get_author_template() && $template = get_archive_template() && $template = get_paged_template() ) : ) : ) : $template = get_index_template(); endif; if ( $template = apply_filters( 'template_include', $template ) ) include( $template );
  11. 11. if ( is_404() && $template = get_404_template() ) : elseif ( is_tag() && $template = get_tag_template() ) : elseif ( is_date() && $template = get_date_template() ) : && $template = get_paged_template() ) : elseif ( is_category() && $template = get_category_template() ) : elseif ( is_author() elseif ( is_archive() elseif ( is_paged() else : && $template = get_author_template() && $template = get_archive_template() ) : ) : $template = get_index_template(); endif; if ( $template = apply_filters( 'template_include', $template ) ) include( $template );
  12. 12. if ( is_404() && $template = get_404_template() ) : elseif ( is_tag() && $template = get_tag_template() ) : elseif ( is_date() && $template = get_date_template() ) : elseif ( is_category() && $template = get_category_template() ) : elseif ( is_author() elseif ( is_archive() elseif ( is_paged() else : && $template = get_author_template() && $template = get_archive_template() && $template = get_paged_template() ) : ) : ) : $template = get_index_template(); endif; if ( $template = apply_filters( 'template_include', $template ) ) include( $template );
  13. 13. if ( is_404() && $template = get_404_template() ) : elseif ( is_tag() && $template = get_tag_template() ) : elseif ( is_date() && $template = get_date_template() ) : elseif ( is_category() && $template = get_category_template() ) : elseif ( is_author() elseif ( is_archive() elseif ( is_paged() else : && $template = get_author_template() && $template = get_archive_template() && $template = get_paged_template() ) : ) : ) : $template = get_index_template(); endif; if ( $template = apply_filters( 'template_include', $template ) ) include( $template );
  14. 14. // get_author_template() $templates[] = "author-{$author->nicename}.php"; $templates[] = "author-{$author->ID}.php"; $templates[] = 'author.php'; $template = locate_template( $templates );
  15. 15. if ( is_404() && $template = get_404_template() ) : elseif ( is_tag() && $template = get_tag_template() ) : elseif ( is_date() && $template = get_date_template() ) : elseif ( is_category() && $template = get_category_template() ) : elseif ( is_author() elseif ( is_archive() elseif ( is_paged() else : && $template = get_author_template() && $template = get_archive_template() && $template = get_paged_template() ) : ) : ) : $template = get_index_template(); endif; if ( $template = apply_filters( 'template_include', $template ) ) include( $template );
  16. 16. if ( $template = apply_filters( 'template_include', $template ) ) include( $template );
  17. 17. function my_template_include( $template ) { if ( my_is_maintenance() && $located = locate_template( 'maintenance.php' ) ) $template = $located; return $template; } add_filter( 'template_include', 'my_template_include' );
  18. 18. locate_template( array( 'foo.php', 'bar.php', 'baz.php' ) ); // // // // // // child/foo.php parent/foo.php child/bar.php parent/bar.php child/baz.php parent/baz.php
  19. 19. locate_template( 'related-posts.php', true ); // child/related-posts.php // parent/related-posts.php // vs: require get_template_directory() . 'related-posts.php';
  20. 20. wp-includes/template-loader.php wp-includes/general-template.php wp-includes/template.php
  21. 21. kovshenin.com/wcsof2013

×