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