WordPress:Include Tags
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.
模板include tags是用在模板 文件内(例如index.php)以执行其它模板文件内的HTML 和PHP (例如header.php)。PHP有一个内置的include()声明,但是这些WordPress模板标签使得包含某些特别的文件变得更加简单。
See WordPress:Using Themes and WordPress:Theme Development for more information about Templates and Themes.
The Header Template
标题模板
<?php get_header(); ?>
<?php get_header(); ?>
This tag includes the file header.php from your current theme's directory. If that file is not found, it will instead include wp-content/themes/default/header.php.
这个标签包含来自当前主题目录的文件header.php。如果没有发现这个文件,标签会包含wp-content/themes/default/header.php。
页底文字模板
<?php get_footer(); ?>
<?php get_footer(); ?>
This tag includes the file footer.php from your current theme's directory. If that file is not found, it will instead include wp-content/themes/default/footer.php.
这个标签包含来自当前主题目录的文件footer.php。如果没有发现这个文件,标签会包含wp-content/themes/default/footer.php。
The Sidebar Template
工具条模板
<?php get_sidebar(); ?>
<?php get_sidebar(); ?>
This tag includes the file sidebar.php from your current theme's directory. If that file is not found, it will instead include wp-content/themes/default/sidebar.php.
这个标签包含当前主题目录的文件sidebar.php。如果没有发现这个文件,标签就会包含wp-content/themes/default/sidebar.php。
<?php get_sidebar('right'); ?>
<?php get_sidebar('right'); ?>
Causes the template TEMPLATEPATH . 'sidebar-right.php'
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 WordPress:Version 2.5.
导致模板TEMPLATEPATH . 'sidebar-right.php'
被包含其中。注:能够规定一个特别的工具条,指的是一个主题中可以使用多个工具条模板,是在2.5版本中添加的。
The Comments Template
评论模板
<?php comments_template(); ?>
<?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-content/themes/default/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.
这个标签包含来自当前主题目录的文件comments.php。如果没有发现这个文件,主题会包含wp-content/themes/default/comments.php。要在主索引或者归档网页上显示评论,你需要将$withcomments变数设置为"1",才能够访问这个标签。
Including Any Template
包含任何模板
WordPress offers the above tags for including those specific WordPress:Templates, but there is also a convenient way to include any file. To do so, you will need to use the include PHP function, and a constant WordPress conveniently defines for you to make things easy: TEMPLATEPATH.
WordPress提供了上述标签,用来包含这些特别的模板,但是还有一个更简便的方法,能够包含任何文件。要使用这种方法,你需要使用include PHP函数,和一个WordPress能够方便地为你定义的一个恒量,使得问题变得更加简单:TEMPLATEPATH。
Suppose you want to include a file called header2.php. Just insert the following line in your template where you want that file's information to appear.
假如你想要包含一个称为header2.php的文件。只要将下面的这些行插入到模板中,你想要文件信息显示的位置中。
<?php include (TEMPLATEPATH . '/header2.php'); ?>
<?php include (TEMPLATEPATH . '/header2.php'); ?>
You could, for example, use this as a means of including a different header instead of the normal header.php which would be included with [[WordPress:#The Header Template|get_header()]].
例如,你可以使用这个作为包含一个不同的标题而不是正常的header.php的方式,header.php可能包含在[[WordPress:#The Header Template|get_header()]]。
NOTE: TEMPLATEPATH is a reference to the absolute path to the current theme directory (without the / at the end). For information on referencing URIs rather than including files, see Referencing Files From a Template.
注: TEMPLATEPATH是一个到达当前主题目录的绝对路径的一个reference(结尾没有/)。关于referencing URI而不是包含文件的信息,请看看从一个模板中Referencing 文件。
Example
例子
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).
下面是有关"HTTP 404:没有找到"错误模板的一个非常简单的例子(可能包含在你的主题中作为404.php)。
<?php get_header(); ?>
<h2>Error 404 - Not Found
<?php get_sidebar(); ?> <?php get_footer(); ?>
<?php get_header(); ?>
<h2>Error 404 - Not Found
<?php get_sidebar(); ?> <?php get_footer(); ?>
Parameters
参数
These tags do not accept any parameters. 这些标签不接受任何参数。 模板:No Param Tag Footer