WordPress: Include Tags:修订间差异
(新页面: The Template '''include tags''' are used within one Template file (for example <tt>index.php</tt>) to execute the HTML and [[WordPress:...) |
无编辑摘要 |
||
第1行: | 第1行: | ||
The Template '''include tags''' are used within one [[WordPress:Templates|Template]] file (for example <tt>index.php</tt>) to execute the [[WordPress:Glossary#HTML|HTML]] and [[WordPress: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 [[WordPress:Templates|Template]] file (for example <tt>index.php</tt>) to execute the [[WordPress:Glossary#HTML|HTML]] and [[WordPress: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. | ||
模板'''include tags'''是用在[[WordPress:Templates|模板]] 文件内(例如<tt>index.php</tt>)以执行其它模板文件内的[[WordPress:Glossary#HTML|HTML]] 和[[WordPress:Glossary#PHP|PHP]] (例如<tt>header.php</tt>)。[http://www.php.net PHP]有一个内置的[http://us3.php.net/manual/en/function.include.php include()]声明,但是这些WordPress模板标签使得包含某些特别的文件变得更加简单。 | |||
See [[WordPress:Using Themes]] and [[WordPress:Theme Development]] for more information about Templates and Themes. | See [[WordPress:Using Themes]] and [[WordPress:Theme Development]] for more information about Templates and Themes. | ||
关于模板和主题的更多的信息,请看看[[WordPress:Using Themes|使用主题]] 和[[WordPress:Theme Development|主题发展]]。 | |||
== The Header Template == | == The Header Template == | ||
== 标题模板 == | |||
<?php get_header(); ?> | <?php get_header(); ?> | ||
<?php get_header(); ?> | |||
This tag includes the file <tt>header.php</tt> from your current theme's directory. If that file is not found, it will instead include <tt>wp-content/themes/default/header.php</tt>. | This tag includes the file <tt>header.php</tt> from your current theme's directory. If that file is not found, it will instead include <tt>wp-content/themes/default/header.php</tt>. | ||
这个标签包含来自当前主题目录的文件<tt>header.php</tt>。如果没有发现这个文件,标签会包含<tt>wp-content/themes/default/header.php</tt>。 | |||
== The Footer Template == | == The Footer Template == | ||
== 页底文字模板 == | |||
<?php get_footer(); ?> | <?php get_footer(); ?> | ||
<?php get_footer(); ?> | |||
This tag includes the file <tt>footer.php</tt> from your current theme's directory. If that file is not found, it will instead include <tt>wp-content/themes/default/footer.php</tt>. | This tag includes the file <tt>footer.php</tt> from your current theme's directory. If that file is not found, it will instead include <tt>wp-content/themes/default/footer.php</tt>. | ||
这个标签包含来自当前主题目录的文件<tt>footer.php</tt>。如果没有发现这个文件,标签会包含<tt>wp-content/themes/default/footer.php</tt>。 | |||
== The Sidebar Template == | == The Sidebar Template == | ||
== 工具条模板 == | |||
<?php get_sidebar(); ?> | <?php get_sidebar(); ?> | ||
<?php get_sidebar(); ?> | |||
This tag includes the file <tt>sidebar.php</tt> from your current theme's directory. If that file is not found, it will instead include <tt>wp-content/themes/default/sidebar.php</tt>. | This tag includes the file <tt>sidebar.php</tt> from your current theme's directory. If that file is not found, it will instead include <tt>wp-content/themes/default/sidebar.php</tt>. | ||
这个标签包含当前主题目录的文件<tt>sidebar.php</tt>。如果没有发现这个文件,标签就会包含<tt>wp-content/themes/default/sidebar.php</tt>。 | |||
<?php get_sidebar('right'); ?> | <?php get_sidebar('right'); ?> | ||
<?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 [[WordPress:Version 2.5]]. | 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 [[WordPress:Version 2.5]]. | ||
导致模板<code>TEMPLATEPATH . 'sidebar-right.php'</code>被包含其中。注:能够规定一个特别的工具条,指的是一个主题中可以使用多个工具条模板,是在[[WordPress:Version 2.5|2.5版本]]中添加的。 | |||
== The Comments Template == | == The Comments Template == | ||
== 评论模板 == | |||
<?php comments_template(); ?> | <?php comments_template(); ?> | ||
<?php comments_template(); ?> | |||
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 <tt>wp-content/themes/default/comments.php</tt>. 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. | 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 <tt>wp-content/themes/default/comments.php</tt>. 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. | ||
这个标签包含来自当前主题目录的文件<tt>comments.php</tt>。如果没有发现这个文件,主题会包含<tt>wp-content/themes/default/comments.php</tt>。要在主索引或者归档网页上显示评论,你需要将<tt>$withcomments</tt>变数设置为<tt>"1"</tt>,才能够访问这个标签。 | |||
== Including Any Template == | == 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 <tt>[http://us2.php.net/manual/en/function.include.php include]</tt> [[WordPress:Glossary#PHP|PHP]] function, and a constant WordPress conveniently defines for you to make things easy: <tt>TEMPLATEPATH</tt>. | 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 <tt>[http://us2.php.net/manual/en/function.include.php include]</tt> [[WordPress:Glossary#PHP|PHP]] function, and a constant WordPress conveniently defines for you to make things easy: <tt>TEMPLATEPATH</tt>. | ||
WordPress提供了上述标签,用来包含这些特别的[[WordPress:Templates|模板]],但是还有一个更简便的方法,能够包含''任何''文件。要使用这种方法,你需要使用<tt>[http://us2.php.net/manual/en/function.include.php include]</tt> [[WordPress:Glossary#PHP|PHP]]函数,和一个WordPress能够方便地为你定义的一个恒量,使得问题变得更加简单:<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. | 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. | ||
假如你想要包含一个称为<tt>header2.php</tt>的文件。只要将下面的这些行插入到模板中,你想要文件信息显示的位置中。 | |||
<?php include (TEMPLATEPATH . '/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 <tt>header.php</tt> which would be included with <tt>[[WordPress:#The Header Template|get_header()]]</tt>. | 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>[[WordPress:#The Header Template|get_header()]]</tt>. | ||
例如,你可以使用这个作为包含一个不同的标题而不是正常的<tt>header.php</tt>的方式,<tt>header.php</tt>可能包含在<tt>[[WordPress:#The Header Template|get_header()]]</tt>。 | |||
'''NOTE''': <tt>TEMPLATEPATH</tt> 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 [[WordPress:Theme Development#Referencing Files From a Template|Referencing Files From a Template]]. | '''NOTE''': <tt>TEMPLATEPATH</tt> 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 [[WordPress:Theme Development#Referencing Files From a Template|Referencing Files From a Template]]. | ||
'''注''': <tt>TEMPLATEPATH</tt>是一个到达当前主题目录的绝对路径的一个reference(结尾没有/)。关于referencing URI而不是包含文件的信息,请看看[[WordPress:Theme Development#Referencing Files From a Template|从一个模板中Referencing 文件]]。 | |||
== Example == | == Example == | ||
== 例子 == | |||
The following is a ''very'' simple example of a template for an "HTTP 404: Not Found" error (which you could include in your [[WordPress:Theme Development|Theme]] as <tt>404.php</tt>). | The following is a ''very'' simple example of a template for an "HTTP 404: Not Found" error (which you could include in your [[WordPress:Theme Development|Theme]] as <tt>404.php</tt>). | ||
下面是有关"HTTP 404:没有找到"错误模板的一个''非常''简单的例子(可能包含在你的[[WordPress:Theme Development|主题]]中作为<tt>404.php</tt>)。 | |||
<?php get_header(); ?> | <?php get_header(); ?> | ||
<h2>Error 404 - Not Found</h2> | |||
<?php get_sidebar(); ?> | |||
<?php get_footer(); ?> | |||
<?php get_header(); ?> | |||
<h2>Error 404 - Not Found</h2> | <h2>Error 404 - Not Found</h2> | ||
<?php get_sidebar(); ?> | <?php get_sidebar(); ?> | ||
第53行: | 第108行: | ||
== Parameters == | == Parameters == | ||
== 参数 == | |||
These tags do not accept any parameters. | These tags do not accept any parameters. | ||
这些标签不接受任何参数。 | |||
<!-- == Related == | <!-- == Related == | ||
第63行: | 第120行: | ||
--> | --> | ||
{{No Param Tag Footer}} | {{No Param Tag Footer}} | ||
<!-- == 相关的 == | |||
{{标签 总 标签}} | |||
{{没有Param 标签 页底文字}} | |||
--> | |||
{{没有 Param标签 页底文字}} |
2008年7月11日 (五) 17:31的版本
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