m (add links and →Changelog) |
|||
(22 intermediate revisions by 10 users not shown) | |||
Line 1: | Line 1: | ||
{{Languages| |
{{Languages| |
||
+ | {{en|Include Tags}} |
||
{{ja|インクルードタグ}} |
{{ja|インクルードタグ}} |
||
+ | {{pt-br|Tags include}} |
||
+ | {{mk|Ознаки за вклучување}} |
||
}} |
}} |
||
+ | |||
+ | == Include Tags == |
||
The Template '''include tags''' are used within one [[Templates|Template]] file (for example <tt>index.php</tt>) to execute the [[Glossary#HTML|HTML]] and [[Glossary#PHP|PHP]] found in another template file (for example <tt>header.php</tt>). [http://www.php.net PHP] has a built in [http://us3.php.net/manual/en/function.include.php include()] statement for this purpose, but these WordPress template tags make including certain specific files much easier. |
The Template '''include tags''' are used within one [[Templates|Template]] file (for example <tt>index.php</tt>) to execute the [[Glossary#HTML|HTML]] and [[Glossary#PHP|PHP]] found in another template file (for example <tt>header.php</tt>). [http://www.php.net PHP] has a built in [http://us3.php.net/manual/en/function.include.php include()] statement for this purpose, but these WordPress template tags make including certain specific files much easier. |
||
See [[Using Themes]] and [[Theme Development]] for more information about Templates and Themes. |
See [[Using Themes]] and [[Theme Development]] for more information about Templates and Themes. |
||
+ | |||
+ | == Function Reference == |
||
+ | |||
+ | {| cellspacing="10" width="100%" |
||
+ | |- valign="top" |
||
+ | | width="50%" | |
||
+ | |||
+ | {| class="widefat" |
||
+ | |- style="background:#464646; color:#d7d7d7;" |
||
+ | ! '''Include Generic Files''' |
||
+ | |- |
||
+ | | |
||
+ | * <tt>[[Function Reference/get_header | get_header()]]</tt> |
||
+ | * <tt>[[Function Reference/get_footer | get_footer()]]</tt> |
||
+ | * <tt>[[Function Reference/get_sidebar | get_sidebar()]]</tt> |
||
+ | * <tt>[[Function Reference/get_template_part | get_template_part()]]</tt> |
||
+ | |} |
||
+ | |||
+ | | width="50%" | |
||
+ | |||
+ | {| class="widefat" |
||
+ | |- style="background:#464646; color:#d7d7d7;" |
||
+ | ! '''Include Other Components''' |
||
+ | |- |
||
+ | | |
||
+ | * <tt>[[Function Reference/get_search_form | get_search_form()]]</tt> |
||
+ | * <tt>[[Function Reference/comments_template | comments_template()]]</tt> |
||
+ | |||
+ | |||
+ | |} |
||
+ | |||
+ | |} |
||
== The Header Template == |
== The Header Template == |
||
Line 11: | Line 48: | ||
<?php get_header(); ?> |
<?php get_header(); ?> |
||
− | + | The <tt>[[Function Reference/get_header | get_header()]]</tt> tag includes the file <tt>header.php</tt> or <tt>header-{name}.php</tt> from your current theme's directory. If that file is not found, it will instead include {{Trac|wp-includes/theme-compat/header.php}}. |
|
== The Footer Template == |
== The Footer Template == |
||
Line 17: | Line 54: | ||
<?php get_footer(); ?> |
<?php get_footer(); ?> |
||
− | + | The <tt>[[Function Reference/get_footer | get_footer()]]</tt> tag includes the file <tt>footer.php</tt> or <tt>footer-{name}.php</tt> from your current theme's directory. If that file is not found, it will instead include {{Trac|wp-includes/theme-compat/footer.php}}. |
|
== The Sidebar Template == |
== The Sidebar Template == |
||
Line 23: | Line 60: | ||
<?php get_sidebar(); ?> |
<?php get_sidebar(); ?> |
||
− | + | The <tt>[[Function Reference/get_sidebar | get_sidebar()]]</tt> tag includes the file <tt>sidebar.php</tt> or <tt>sidebar-{name}.php</tt> from your current theme's directory. If that file is not found, it will instead include {{Trac|wp-includes/theme-compat/sidebar.php}}. |
|
+ | == Custom Template files == |
||
− | <?php get_sidebar('right'); ?> |
||
⚫ | |||
− | Causes the template <code>TEMPLATEPATH . 'sidebar-right.php'</code> to be included. Note: the ability to specify a particular sidebar, meaning more than one sidebar template can be used in a theme, was added with [[Version 2.5]]. |
||
+ | The <tt>[[Function Reference/get_template_part | get_template_part()]]</tt> tag includes the file <tt>{slug}.php</tt> or <tt>{slug}-{name}.php</tt> from your current theme's directory, a custom Include Tags other than header, sidebar, footer. |
||
⚫ | |||
+ | == The Search Form Template == |
||
⚫ | |||
+ | <?php get_search_form(); ?> |
||
⚫ | This tag includes the file <tt>comments.php</tt> from your current theme's directory. If that file is not found, it will instead include |
||
+ | The <tt>[[Function Reference/get_search_form | get_search_form()]]</tt> tag includes the file <tt>searchform.php</tt> from your current theme's directory. If that file is not found, it will generate the search form. |
||
⚫ | |||
+ | See also [[Function Reference/get_search_form|get_search_form]] and [[Migrating Plugins and Themes to 2.7#The Search Form Template Tag|Migrating Plugins and Themes to 2.7]] for more detail. |
||
− | WordPress offers the above tags for including those specific [[Templates]], but there is also a convenient way to include ''any'' file. To do so, you will need to use the <tt>[http://us2.php.net/manual/en/function.include.php include]</tt> [[Glossary#PHP|PHP]] function, and a constant WordPress conveniently defines for you to make things easy: <tt>TEMPLATEPATH</tt>. |
||
⚫ | |||
− | Suppose you want to include a file called <tt>header2.php</tt>. Just insert the following line in your template where you want that file's information to appear. |
||
− | <?php |
+ | <?php comments_template(); ?> |
− | |||
− | You could, for example, use this as a means of including a different header instead of the normal <tt>header.php</tt> which would be included with <tt>[[#The Header Template|get_header()]]</tt>. |
||
⚫ | This tag includes the file <tt>comments.php</tt> from your current theme's directory. If that file is not found, it will instead include {{Trac|wp-includes/theme-compat/comments.php}}. To display comments on the main index or archive pages, you'll need to set the <tt>$withcomments</tt> variable to <tt>"1"</tt> before calling this tag. |
||
− | '''NOTE''': |
||
− | * <tt>TEMPLATEPATH</tt> is a reference to the absolute path to the current template directory (without the / at the end). For information on referencing URIs rather than including files, see [[Theme Development#Referencing Files From a Template|Referencing Files From a Template]]. |
||
− | * <tt>STYLESHEETPATH</tt> should be used to include a file located within a [[Theme Development#Theme Style Sheet|child theme]]. |
||
== Example == |
== Example == |
||
Line 55: | Line 88: | ||
<pre> |
<pre> |
||
<?php get_header(); ?> |
<?php get_header(); ?> |
||
+ | <?php get_template_part('nav'); ?> |
||
<h2>Error 404 - Not Found</h2> |
<h2>Error 404 - Not Found</h2> |
||
<?php get_sidebar(); ?> |
<?php get_sidebar(); ?> |
||
Line 61: | Line 95: | ||
== Parameters == |
== Parameters == |
||
− | < |
+ | [[Include_Tags#The Header Template|<code>get_header()</code>]], [[Include_Tags#The Footer Template|<code>get_footer()</code>]] and [[Include_Tags#The Sidebar Template|<code>get_sidebar()</code>]] accepts one parameter: |
− | {{Parameter|$name|string| |
+ | {{Parameter|$name|string|Calls for sidebar-{name}.php. For Example: <tt>sidebar-right.php</tt>, <tt>header-single.php</tt> or <tt>footer-8.php</tt>.|optional}} |
+ | |||
+ | [[Include_Tags#Custom Template files|<code>get_template_part()</code>]] accepts two parameters: |
||
+ | {{Parameter|$slug|string|Calls for {slug}.php. For Example: <tt>nav.php</tt>}} |
||
+ | {{Parameter|$name|string|Calls for {slug}-{name}.php. For Example: <tt>nav-home.php</tt>|optional}} |
||
== Changelog == |
== Changelog == |
||
+ | * [[Version 1.5|1.5]] : |
||
⚫ | |||
+ | ** [[Include_Tags#The Header Template|<code>get_header()</code>]] was added to include the template header. |
||
+ | ** [[Include_Tags#The Footer Template|<code>get_footer()</code>]] was added to include the template footer. |
||
+ | ** [[Include_Tags#The Sidebar Template|<code>get_sidebar()</code>]] was added to include the template sidebar. |
||
+ | |||
+ | * [[Version 2.5|2.5]] : |
||
⚫ | |||
+ | |||
+ | * [[Version 2.7|2.7]] : |
||
+ | ** The ''name'' parameter was added to [[Include_Tags#The Header Template|<code>get_header()</code>]]. |
||
+ | ** The ''name'' parameter was added to [[Include_Tags#The Footer Template|<code>get_footer()</code>]]. |
||
+ | ** [[Include_Tags#The Search From Template|<code>get_search_form()</code>]] was added to include the search form. |
||
+ | |||
+ | * [[Version 3.0|3.0]] : |
||
+ | ** [[Include_Tags#Custom Template files|<code>get_template_part()</code>]] was added to include the template other generic files. |
||
+ | |||
+ | == Source File == |
||
+ | * Browse source: {{Trac|wp-includes/general-template.php}} |
||
− | + | == Related == |
|
+ | {{Include Tags}} |
||
− | {{Tag |
+ | {{Tag Footer}} |
− | {{No Param Tag Footer}} |
||
− | --> |
||
− | {{No Param Tag Footer}} |
||
[[Category:Design and Layout]] |
[[Category:Design and Layout]] |
Languages: English • 日本語 Português do Brasil • Македонски • (Add your language)
The Template include tags are used within one Template file (for example index.php) to execute the HTML and PHP found in another template file (for example header.php). PHP has a built in include() statement for this purpose, but these WordPress template tags make including certain specific files much easier.
See Using Themes and Theme Development for more information about Templates and Themes.
|
|
<?php get_header(); ?>
The get_header() tag includes the file header.php or header-{name}.php from your current theme's directory. If that file is not found, it will instead include wp-includes/theme-compat/header.php
.
<?php get_footer(); ?>
The get_footer() tag includes the file footer.php or footer-{name}.php from your current theme's directory. If that file is not found, it will instead include wp-includes/theme-compat/footer.php
.
<?php get_sidebar(); ?>
The get_sidebar() tag includes the file sidebar.php or sidebar-{name}.php from your current theme's directory. If that file is not found, it will instead include wp-includes/theme-compat/sidebar.php
.
<?php get_template_part(); ?>
The get_template_part() tag includes the file {slug}.php or {slug}-{name}.php from your current theme's directory, a custom Include Tags other than header, sidebar, footer.
<?php get_search_form(); ?>
The get_search_form() tag includes the file searchform.php from your current theme's directory. If that file is not found, it will generate the search form.
See also get_search_form and Migrating Plugins and Themes to 2.7 for more detail.
<?php comments_template(); ?>
This tag includes the file comments.php from your current theme's directory. If that file is not found, it will instead include wp-includes/theme-compat/comments.php
. To display comments on the main index or archive pages, you'll need to set the $withcomments variable to "1" before calling this tag.
The following is a very simple example of a template for an "HTTP 404: Not Found" error (which you could include in your Theme as 404.php).
<?php get_header(); ?> <?php get_template_part('nav'); ?> <h2>Error 404 - Not Found</h2> <?php get_sidebar(); ?> <?php get_footer(); ?>
get_header()
, get_footer()
and get_sidebar()
accepts one parameter:
get_template_part()
accepts two parameters:
get_header()
was added to include the template header.get_footer()
was added to include the template footer.get_sidebar()
was added to include the template sidebar.get_sidebar()
.get_header()
.get_footer()
.get_search_form()
was added to include the search form.get_template_part()
was added to include the template other generic files.wp-includes/general-template.php
Include Tags