Templating WordPress
-
Upload
konstantin-kovshenin -
Category
Technology
-
view
5.420 -
download
1
description
Transcript of Templating WordPress
![Page 1: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/1.jpg)
Templating WordPressKonstantin KovsheninAutomattic
![Page 2: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/2.jpg)
![Page 3: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/3.jpg)
![Page 4: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/4.jpg)
author-$nicename.phpauthor-$id.phpauthor.phparchive.phppaged.phpindex.php
![Page 5: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/5.jpg)
$templates = array( 'foo.php', 'bar.php', 'baz.php',);$template = locate_template( $templates );
![Page 6: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/6.jpg)
function get_sidebar( $name = null ) { $templates = array(); if ( '' !== $name ) $templates[] = "sidebar-{$name}.php"; $templates[] = 'sidebar.php';
locate_template( $templates, true );}
![Page 7: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/7.jpg)
get_sidebar( 'left' );// sidebar-left.php// sidebar.php
![Page 8: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/8.jpg)
get_header( 'foo' );// header-foo.php// header.php
get_footer( 'bar' );// footer-bar.php// footer.php
![Page 9: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/9.jpg)
get_template_part( 'foo', 'bar' );// foo-bar.php// foo.php
![Page 10: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/10.jpg)
get_template_part( 'content', get_post_format() );
// content-gallery.php// content-quote.php// content-image.php// ...// content.php
![Page 11: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/11.jpg)
template-loader.php
![Page 12: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/12.jpg)
if ( is_404() && $template = get_404_template() ) : elseif ( is_category() && $template = get_category_template() ) : elseif ( is_tag() && $template = get_tag_template() ) : elseif ( is_author() && $template = get_author_template() ) : elseif ( is_date() && $template = get_date_template() ) : elseif ( is_archive() && $template = get_archive_template() ) : elseif ( is_paged() && $template = get_paged_template() ) : else : $template = get_index_template(); endif;
if($template=apply_filters('template_include',$template)) include( $template );
![Page 13: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/13.jpg)
if ( is_404() && $template = get_404_template() ) : elseif ( is_category() && $template = get_category_template() ) : elseif ( is_tag() && $template = get_tag_template() ) : elseif ( is_author() && $template = get_author_template() ) : elseif ( is_date() && $template = get_date_template() ) : elseif ( is_archive() && $template = get_archive_template() ) : elseif ( is_paged() && $template = get_paged_template() ) : else : $template = get_index_template(); endif;
if($template=apply_filters('template_include',$template)) include( $template );
![Page 14: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/14.jpg)
if ( is_404() && $template = get_404_template() ) : elseif ( is_category() && $template = get_category_template() ) : elseif ( is_tag() && $template = get_tag_template() ) : elseif ( is_author() && $template = get_author_template() ) : elseif ( is_date() && $template = get_date_template() ) : elseif ( is_archive() && $template = get_archive_template() ) : elseif ( is_paged() && $template = get_paged_template() ) : else : $template = get_index_template(); endif;
if($template=apply_filters('template_include',$template)) include( $template );
![Page 15: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/15.jpg)
if ( is_404() && $template = get_404_template() ) : elseif ( is_category() && $template = get_category_template() ) : elseif ( is_tag() && $template = get_tag_template() ) : elseif ( is_author() && $template = get_author_template() ) : elseif ( is_date() && $template = get_date_template() ) : elseif ( is_archive() && $template = get_archive_template() ) : elseif ( is_paged() && $template = get_paged_template() ) : else : $template = get_index_template(); endif;
if($template=apply_filters('template_include', $template ) ) include( $template );
![Page 16: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/16.jpg)
// get_author_template()
$templates[] = "author-{$author->nicename}.php";$templates[] = "author-{$author->ID}.php";$templates[] = 'author.php';
$template = locate_template( $templates );
![Page 17: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/17.jpg)
if ( is_404() && $template = get_404_template() ) : elseif ( is_category() && $template = get_category_template() ) : elseif ( is_tag() && $template = get_tag_template() ) : elseif ( is_author() && $template = get_author_template() ) : elseif ( is_date() && $template = get_date_template() ) : elseif ( is_archive() && $template = get_archive_template() ) : elseif ( is_paged() && $template = get_paged_template() ) : else : $template = get_index_template(); endif;
if($template=apply_filters('template_include',$template)) include( $template );
![Page 18: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/18.jpg)
if($template=apply_filters( 'template_include', $template ) ) include( $template );
![Page 19: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/19.jpg)
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' );
![Page 20: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/20.jpg)
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
![Page 21: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/21.jpg)
locate_template( 'related-posts.php', true );// child/related-posts.php// parent/related-posts.php
// vs: require get_template_directory() . 'related-posts.php';
![Page 22: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/22.jpg)
wp-includes/template-loader.phpwp-includes/general-template.phpwp-includes/template.php
![Page 23: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/23.jpg)
kovshenin.com/wcsof2013
![Page 24: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/24.jpg)
![Page 25: Templating WordPress](https://reader033.fdocuments.us/reader033/viewer/2022052620/5578ab2ed8b42a4d4b8b4a49/html5/thumbnails/25.jpg)