インクルードタグ – WordPress*リファレンス

別のテンプレートファイル(例えば、header.php)の中でHTMLを実行する1個のTemplateファイル(例えば、index.php)とPHPの中で見つけられて、Templateは使用されるタグを含んでいます。 PHPはinclude()声明をこのために建てさせますが、これらのWordPressテンプレートタグで、ある特定のファイルを含んでいるのははるかに簡単になります。

TemplatesとThemesに関する詳しい情報に関してUsing ThemesとTheme Developmentを見てください。

原文⇒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.

The Header Template

<?php get_header(); ?>

このタグをあなたの現在のテーマのディレクトリからheader.phpファイルが含まれています。もしそのファイルが存在しない場合は、代わりにwp-content/themes/default/header.phpが含まれます。

原文⇒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.

The Footer Template

<?php get_footer(); ?>

このタグをあなたの現在のテーマのディレクトリからfooter.phpファイルが含まれています。もしそのファイルが存在しない場合は、代わりにwp-content/themes/default/footer.phpが含まれます。

原文⇒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.

The Sidebar Template

<?php get_sidebar(); ?>

このタグをあなたの現在のテーマのディレクトリからsidebar.phpファイルが含まれています。もしそのファイルが存在しない場合は、代わりにwp-content/themes/default/sidebar.phpが含まれます。

原文⇒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.

<?php get_sidebar('right'); ?>

原因は、テンプレートTEMPLATEPATH 、’sidebar-right.php ‘が含まれる。注:この機能は、特定のサイドバーを指定するために、 1つ以上の意味をテーマにサイドバーを使用できますが、バージョン2.5で追加されたテンプレートです。

原文⇒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 Version 2.5.

The Comments Template

<?php comments_template(); ?>

このタグをあなたの現在のテーマのディレクトリからcomments.phpファイルが含まれています。もしそのファイルが存在しない場合は、代わりにwp-content/themes/default/comments.phpが含まれます。メインのインデックスやアーカイブページにコメントを表示するには、 $ withcomments 1 “に変数を設定する”このタグを呼び出す前に必要になるでしょう。

原文⇒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.

Including Any Template

ワードプレスは、特定のテンプレートを含むが、上記のタグを提供していますがまた、任意のファイルを含めるには、便利な方法です。これを行うには、物事を簡単に: TEMPLATEPATHに便利なPHPの関数を定義し、一定のワードプレスなどを使用する必要があります。

原文⇒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 include PHP function, and a constant WordPress conveniently defines for you to make things easy: TEMPLATEPATH.

あなたheader2.phpと呼ばれるファイルを含むようにしたいと仮定します。だけで、そのファイルの情報を表示するテンプレートには、以下の行を挿入します。

原文⇒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.

<?php include (TEMPLATEPATH . '/header2.php'); ?>

たとえば、get_header()これに含まれる通常のheader.phpの代わりに別のヘッダを含むための手段として使うことができます。

注:

*現在のTEMPLATEPATH (なし/終了時に)ディレクトリのテンプレートへの絶対パスへの参照です。というよりも参照するファイルなどのURIに関する情報については、テンプレートからのファイルのリファレンスを参照してください。
* STYLESHEETPATH子供をテーマに位置し、ファイルを使用する必要があります。

原文⇒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 get_header().

NOTE:

* TEMPLATEPATH 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 Referencing Files From a Template.
* STYLESHEETPATH should be used to include a file located within a child theme.

Example

これが”HTTP 404: Not Found”エラーテンプレートの非常に簡単な例である、”HTTP 404: Not Found”エラー(あなたが404.phpとしてThemeに含むことができた)。

原文⇒ 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(); ?>
<h2>Error 404 - Not Found</h2>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Parameters

get_header()、get_footer()、comments_template()タグ、パラメータを受け付けておりませんが、get_sidebar()1つのパラメータを受け付けます:

原文⇒get_header(), get_footer() and comments_template() tags do not accept parameters, but get_sidebar() accepts one parameter:

$name

(string) (optional) get_sidebar()を見てください。
デフォルト: null

原文⇒(string) (optional) See get_sidebar()
Default: null

Changelog

2.5 :get_sidebar()パラメータの名前が登録されました。

原文⇒* 2.5 : The name parameter was added to get_sidebar().

Related

get_header, get_sidebar, get_search_form, comments_template, get_footer


HOME » WordPress*リファレンス » テーマ、テンプレートとカスタマイズ » インクルードタグ – WordPress*リファレンス