SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Downloaden Sie, um offline zu lesen
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";
$templates[] = 'sidebar.php';

}

locate_template( $templates, true );
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
...
content.php
template-loader.php
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 );
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 );
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 );
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 );
// get_author_template()
$templates[] = "author-{$author->nicename}.php";
$templates[] = "author-{$author->ID}.php";
$templates[] = 'author.php';
$template = locate_template( $templates );
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 );
if ( $template = apply_filters(
'template_include', $template ) )
include( $template );
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' );
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
locate_template( 'related-posts.php', true );
// child/related-posts.php
// parent/related-posts.php
// vs: require get_template_directory() .
'related-posts.php';
wp-includes/template-loader.php
wp-includes/general-template.php
wp-includes/template.php
kovshenin.com/wcsof2013
Templating WordPress
Templating WordPress

Weitere ähnliche Inhalte

Was ist angesagt?

Form Script
Form ScriptForm Script
Form Scriptlotlot
 
Declaração de Voto da JSD Golegã no Conselho Municipal Juventude Golegã 2012
Declaração de Voto da JSD Golegã no Conselho Municipal Juventude Golegã 2012Declaração de Voto da JSD Golegã no Conselho Municipal Juventude Golegã 2012
Declaração de Voto da JSD Golegã no Conselho Municipal Juventude Golegã 2012jsdgolega
 
jQuery - Javascript para quem não sabe Javascript
jQuery - Javascript para quem não sabe JavascriptjQuery - Javascript para quem não sabe Javascript
jQuery - Javascript para quem não sabe JavascriptNando Vieira
 
Managen van Verwachtingen.
Managen van Verwachtingen.Managen van Verwachtingen.
Managen van Verwachtingen.Groenewoud
 
Sumahexavector
SumahexavectorSumahexavector
Sumahexavectorjbersosa
 
การแทรกสัญลักษณ์หน้าข้อความ
การแทรกสัญลักษณ์หน้าข้อความการแทรกสัญลักษณ์หน้าข้อความ
การแทรกสัญลักษณ์หน้าข้อความเทวัญ ภูพานทอง
 
Crea un tema compatibile con le ultime novità WordPress
Crea un tema compatibile con le ultime novità WordPressCrea un tema compatibile con le ultime novità WordPress
Crea un tema compatibile con le ultime novità WordPressSkillsAndMore
 
Aeman dee ekkadunnaaru
Aeman dee ekkadunnaaruAeman dee ekkadunnaaru
Aeman dee ekkadunnaaruvenkatesha9
 

Was ist angesagt? (20)

การแทรกรูปภาพ
การแทรกรูปภาพการแทรกรูปภาพ
การแทรกรูปภาพ
 
Introducción a Bolt
Introducción a BoltIntroducción a Bolt
Introducción a Bolt
 
Form Script
Form ScriptForm Script
Form Script
 
Comparison Principle
Comparison PrincipleComparison Principle
Comparison Principle
 
การแทรกรูปภาพ
การแทรกรูปภาพการแทรกรูปภาพ
การแทรกรูปภาพ
 
Declaração de Voto da JSD Golegã no Conselho Municipal Juventude Golegã 2012
Declaração de Voto da JSD Golegã no Conselho Municipal Juventude Golegã 2012Declaração de Voto da JSD Golegã no Conselho Municipal Juventude Golegã 2012
Declaração de Voto da JSD Golegã no Conselho Municipal Juventude Golegã 2012
 
jQuery - Javascript para quem não sabe Javascript
jQuery - Javascript para quem não sabe JavascriptjQuery - Javascript para quem não sabe Javascript
jQuery - Javascript para quem não sabe Javascript
 
Managen van Verwachtingen.
Managen van Verwachtingen.Managen van Verwachtingen.
Managen van Verwachtingen.
 
Index2
Index2Index2
Index2
 
Miniray.php
Miniray.phpMiniray.php
Miniray.php
 
การปรับแต่งตัวอักษร
การปรับแต่งตัวอักษรการปรับแต่งตัวอักษร
การปรับแต่งตัวอักษร
 
Presentación JxNet - Software de Gestión Jurídica Corporativa
Presentación JxNet - Software de Gestión Jurídica CorporativaPresentación JxNet - Software de Gestión Jurídica Corporativa
Presentación JxNet - Software de Gestión Jurídica Corporativa
 
Sumahexavector
SumahexavectorSumahexavector
Sumahexavector
 
การแทรกสัญลักษณ์หน้าข้อความ
การแทรกสัญลักษณ์หน้าข้อความการแทรกสัญลักษณ์หน้าข้อความ
การแทรกสัญลักษณ์หน้าข้อความ
 
การแทรกอักษรศิลป์
การแทรกอักษรศิลป์การแทรกอักษรศิลป์
การแทรกอักษรศิลป์
 
Ryn January 2011
Ryn January 2011Ryn January 2011
Ryn January 2011
 
OFFENSE
OFFENSEOFFENSE
OFFENSE
 
Crea un tema compatibile con le ultime novità WordPress
Crea un tema compatibile con le ultime novità WordPressCrea un tema compatibile con le ultime novità WordPress
Crea un tema compatibile con le ultime novità WordPress
 
The evil consequences of fornication and adultery
The evil consequences of fornication and adulteryThe evil consequences of fornication and adultery
The evil consequences of fornication and adultery
 
Aeman dee ekkadunnaaru
Aeman dee ekkadunnaaruAeman dee ekkadunnaaru
Aeman dee ekkadunnaaru
 

Andere mochten auch

7 Tips for Better WordPress Theme Development
7 Tips for Better WordPress Theme Development7 Tips for Better WordPress Theme Development
7 Tips for Better WordPress Theme DevelopmentKonstantin Kovshenin
 
Road to Platform @ WordPress.com VIP Workshop 2014
Road to Platform @ WordPress.com VIP Workshop 2014Road to Platform @ WordPress.com VIP Workshop 2014
Road to Platform @ WordPress.com VIP Workshop 2014Konstantin Kovshenin
 
Things I Wish I Had Known Before Developing a WordPress Theme
Things I Wish I Had Known Before Developing a WordPress ThemeThings I Wish I Had Known Before Developing a WordPress Theme
Things I Wish I Had Known Before Developing a WordPress ThemeKonstantin Kovshenin
 
Где брать ИДЕИ для написания постов и плагинов WordPress
Где брать ИДЕИ для написания постов и плагинов WordPressГде брать ИДЕИ для написания постов и плагинов WordPress
Где брать ИДЕИ для написания постов и плагинов WordPressMisha Rudrastyh
 
WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)
WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)
WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)Ozh
 
High Performance WordPress
High Performance WordPressHigh Performance WordPress
High Performance WordPressvnsavage
 
Вёрстка по методологии БЭМ
Вёрстка по методологии БЭМВёрстка по методологии БЭМ
Вёрстка по методологии БЭМversusbassz
 
SEO - поведенческие факторы.
SEO - поведенческие факторы.SEO - поведенческие факторы.
SEO - поведенческие факторы.Pavel Karpov
 
следите за-языком-20150709
следите за-языком-20150709следите за-языком-20150709
следите за-языком-20150709Doug Lawrence
 
Premium-темы WordPress
Premium-темы WordPressPremium-темы WordPress
Premium-темы WordPressversusbassz
 
Защищаем WordPress-сайт от хакерских атак
Защищаем WordPress-сайт от хакерских атакЗащищаем WordPress-сайт от хакерских атак
Защищаем WordPress-сайт от хакерских атакRuslan Sukhar
 
WordPress под нагрузкой: масштабирование и отказоустойчивость
WordPress под нагрузкой: масштабирование и отказоустойчивостьWordPress под нагрузкой: масштабирование и отказоустойчивость
WordPress под нагрузкой: масштабирование и отказоустойчивостьKonstantin Kovshenin
 
WordPress: Getting Under the Hood
WordPress: Getting Under the HoodWordPress: Getting Under the Hood
WordPress: Getting Under the HoodScott Taylor
 
Пожиратели памяти в WordPress
Пожиратели памяти в WordPressПожиратели памяти в WordPress
Пожиратели памяти в WordPressKonstantin Kovshenin
 
State of the Word 2014
State of the Word 2014State of the Word 2014
State of the Word 2014photomatt
 
WordPress 4.4 and Beyond
WordPress 4.4 and BeyondWordPress 4.4 and Beyond
WordPress 4.4 and BeyondScott Taylor
 
State of the Word 2016
State of the Word 2016State of the Word 2016
State of the Word 2016photomatt
 
What Makes Great Infographics
What Makes Great InfographicsWhat Makes Great Infographics
What Makes Great InfographicsSlideShare
 

Andere mochten auch (20)

The Settings API
The Settings APIThe Settings API
The Settings API
 
7 Tips for Better WordPress Theme Development
7 Tips for Better WordPress Theme Development7 Tips for Better WordPress Theme Development
7 Tips for Better WordPress Theme Development
 
Road to Platform @ WordPress.com VIP Workshop 2014
Road to Platform @ WordPress.com VIP Workshop 2014Road to Platform @ WordPress.com VIP Workshop 2014
Road to Platform @ WordPress.com VIP Workshop 2014
 
Memory Management in WordPress
Memory Management in WordPressMemory Management in WordPress
Memory Management in WordPress
 
Things I Wish I Had Known Before Developing a WordPress Theme
Things I Wish I Had Known Before Developing a WordPress ThemeThings I Wish I Had Known Before Developing a WordPress Theme
Things I Wish I Had Known Before Developing a WordPress Theme
 
Где брать ИДЕИ для написания постов и плагинов WordPress
Где брать ИДЕИ для написания постов и плагинов WordPressГде брать ИДЕИ для написания постов и плагинов WordPress
Где брать ИДЕИ для написания постов и плагинов WordPress
 
WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)
WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)
WordPress Plugin Unit Tests (FR - WordCamp Paris 2015)
 
High Performance WordPress
High Performance WordPressHigh Performance WordPress
High Performance WordPress
 
Вёрстка по методологии БЭМ
Вёрстка по методологии БЭМВёрстка по методологии БЭМ
Вёрстка по методологии БЭМ
 
SEO - поведенческие факторы.
SEO - поведенческие факторы.SEO - поведенческие факторы.
SEO - поведенческие факторы.
 
следите за-языком-20150709
следите за-языком-20150709следите за-языком-20150709
следите за-языком-20150709
 
Premium-темы WordPress
Premium-темы WordPressPremium-темы WordPress
Premium-темы WordPress
 
Защищаем WordPress-сайт от хакерских атак
Защищаем WordPress-сайт от хакерских атакЗащищаем WordPress-сайт от хакерских атак
Защищаем WordPress-сайт от хакерских атак
 
WordPress под нагрузкой: масштабирование и отказоустойчивость
WordPress под нагрузкой: масштабирование и отказоустойчивостьWordPress под нагрузкой: масштабирование и отказоустойчивость
WordPress под нагрузкой: масштабирование и отказоустойчивость
 
WordPress: Getting Under the Hood
WordPress: Getting Under the HoodWordPress: Getting Under the Hood
WordPress: Getting Under the Hood
 
Пожиратели памяти в WordPress
Пожиратели памяти в WordPressПожиратели памяти в WordPress
Пожиратели памяти в WordPress
 
State of the Word 2014
State of the Word 2014State of the Word 2014
State of the Word 2014
 
WordPress 4.4 and Beyond
WordPress 4.4 and BeyondWordPress 4.4 and Beyond
WordPress 4.4 and Beyond
 
State of the Word 2016
State of the Word 2016State of the Word 2016
State of the Word 2016
 
What Makes Great Infographics
What Makes Great InfographicsWhat Makes Great Infographics
What Makes Great Infographics
 

Mehr von Konstantin Kovshenin

7 убийц производительности WordPress
7 убийц производительности WordPress7 убийц производительности WordPress
7 убийц производительности WordPressKonstantin Kovshenin
 
Будущее WordPress (SPB, 2014)
Будущее WordPress (SPB, 2014)Будущее WordPress (SPB, 2014)
Будущее WordPress (SPB, 2014)Konstantin Kovshenin
 
Как повысить скорость вашего сайта на WordPress
Как повысить скорость вашего сайта на WordPressКак повысить скорость вашего сайта на WordPress
Как повысить скорость вашего сайта на WordPressKonstantin Kovshenin
 
Основые безопасности WordPress
Основые безопасности WordPressОсновые безопасности WordPress
Основые безопасности WordPressKonstantin Kovshenin
 
Цикл разработки WordPress
Цикл разработки WordPressЦикл разработки WordPress
Цикл разработки WordPressKonstantin Kovshenin
 

Mehr von Konstantin Kovshenin (9)

Scaling out with WordPress
Scaling out with WordPressScaling out with WordPress
Scaling out with WordPress
 
7 убийц производительности WordPress
7 убийц производительности WordPress7 убийц производительности WordPress
7 убийц производительности WordPress
 
Будущее WordPress (SPB, 2014)
Будущее WordPress (SPB, 2014)Будущее WordPress (SPB, 2014)
Будущее WordPress (SPB, 2014)
 
Будущее WordPress
Будущее WordPressБудущее WordPress
Будущее WordPress
 
Как повысить скорость вашего сайта на WordPress
Как повысить скорость вашего сайта на WordPressКак повысить скорость вашего сайта на WordPress
Как повысить скорость вашего сайта на WordPress
 
Основые безопасности WordPress
Основые безопасности WordPressОсновые безопасности WordPress
Основые безопасности WordPress
 
Цикл разработки WordPress
Цикл разработки WordPressЦикл разработки WordPress
Цикл разработки WordPress
 
P2
P2P2
P2
 
Секреты WP_Query
Секреты WP_QueryСекреты WP_Query
Секреты WP_Query
 

Templating WordPress

  • 2.
  • 3.
  • 6. function get_sidebar( $name = null ) { $templates = array(); if ( '' !== $name ) $templates[] = "sidebar-{$name}.php"; $templates[] = 'sidebar.php'; } locate_template( $templates, true );
  • 7. get_sidebar( 'left' ); // sidebar-left.php // sidebar.php
  • 8. get_header( 'foo' ); // header-foo.php // header.php get_footer( 'bar' ); // footer-bar.php // footer.php
  • 9. get_template_part( 'foo', 'bar' ); // foo-bar.php // foo.php
  • 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. 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 );
  • 14. 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 );
  • 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. // get_author_template() $templates[] = "author-{$author->nicename}.php"; $templates[] = "author-{$author->ID}.php"; $templates[] = 'author.php'; $template = locate_template( $templates );
  • 17. 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 );
  • 18. if ( $template = apply_filters( 'template_include', $template ) ) include( $template );
  • 19. 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' );
  • 20. 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
  • 21. locate_template( 'related-posts.php', true ); // child/related-posts.php // parent/related-posts.php // vs: require get_template_directory() . 'related-posts.php';