Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Templating WordPress

6,287 views

Published on

At WordCamp Sofia 2013

Published in: Technology, Business
  • Dating for everyone is here: ♥♥♥ http://bit.ly/2F4cEJi ♥♥♥
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Follow the link, new dating source: ♥♥♥ http://bit.ly/2F4cEJi ♥♥♥
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

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

×