どんなテンプレートもインクルードする – WordPress*リファレンス

Sponsored Link

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

Sponsored Link

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.

Including Any Template

WordPressはそれらの特定のTemplatesを含むように上のタグを提供しますが、また、どんなファイルも含む便利な方法があります。 そうするために、あなたは、あなたが事態を簡単にするようにWordPressが便利に定義するインクルードPHP機能、および定数を使用する必要があるでしょう: TEMPLATEPATH。

header2.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.

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に参照をつける情報に関しては、Referencing Files From a Templateを見てください。

原文⇒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 theme directory (without the / at the end). For information on referencing URIs rather than including files, see Referencing Files From a Template.

Sponsored Link