- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
「関数リファレンス/get query template」の版間の差分
提供: WordPress Codex 日本語版
< 関数リファレンス
(クリーンアップ。) |
(Code Reference の get_query_template() をマージ。) |
||
1行目: | 1行目: | ||
− | < | + | == 説明<span id="Description"></span> == |
− | + | ||
− | </ | + | |
− | + | 拡張子を含めずファイル名を指定してテンプレートのパスを取得します。[[関数リファレンス/locate_template|<tt>locate_template()</tt>]] を利用して、テンプレートの有無を親テーマについてもチェックします。他の <tt>get_*_template()</tt> 関数を使わずに、より汎用的なテンプレートの取得が行えます。 | |
− | + | == 使い方<span id="Usage"></span> == | |
+ | |||
+ | <?php get_query_template( $type, $templates ); ?> | ||
+ | |||
+ | == パラメータ<span id="Parameters"></span> == | ||
+ | |||
+ | {{Parameter|$type|文字列|拡張子なしのファイル名。}} | ||
+ | |||
+ | {{Parameter|$templates|配列|テンプレート候補のリスト。|オプション|array()}} | ||
+ | |||
+ | == 戻り値<span id="Return_Values"></span> == | ||
+ | |||
+ | ; (文字列) : テンプレートファイルへのフルパス。 | ||
+ | |||
+ | == 用例<span id="Examples"></span> == | ||
取得したパスのファイルを読み込むには [http://us3.php.net/manual/ja/function.include.php <tt>include()</tt>] や [http://us3.php.net/manual/ja/function.require.php <tt>require()</tt>] が使えます。 | 取得したパスのファイルを読み込むには [http://us3.php.net/manual/ja/function.include.php <tt>include()</tt>] や [http://us3.php.net/manual/ja/function.require.php <tt>require()</tt>] が使えます。 | ||
19行目: | 31行目: | ||
</pre> | </pre> | ||
− | + | == 参考<span id="Notes"></span> == | |
− | = | + | |
− | < | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | </ | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | = | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | * | + | * <tt>$templates</tt> が空の場合、<tt>{$type}.php</tt> を探します。 |
− | + | * 動的なフィルター <tt>[https://developer.wordpress.org/reference/hooks/type_template_hierarchy/ '{$type}_template_hierarchy']</tt> を <tt>$templates</tt> に適用します。 | |
+ | * [[関数リファレンス/locate_template|<tt>locate_template()</tt>]] でテンプレートファイルを特定した後、動的なフィルター <tt>[https://developer.wordpress.org/reference/hooks/type_template/ '{$type}_template']</tt> を適用します。 | ||
− | < | + | == 変更履歴<span id="Change_Log"></span> == |
− | + | ||
− | </ | + | |
新規導入: 1.5.0 | 新規導入: 1.5.0 | ||
− | < | + | == ソースファイル<span id="Source_File"></span> == |
− | + | ||
− | </ | + | |
<tt>get_query_template()</tt> は {{Trac|wp-includes/template.php}} にあります。 | <tt>get_query_template()</tt> は {{Trac|wp-includes/template.php}} にあります。 | ||
− | < | + | == 関連項目<span id="Related"></span> == |
− | + | ||
− | </ | + | |
{{Tag Footer}} | {{Tag Footer}} | ||
− | {{原文|Function Reference/get query template|153412}} | + | <!-- {{原文|Function Reference/get query template|153412}} 05:59, 14 August 2015 Miccweb 版 --> |
+ | 最新英語版: [https://developer.wordpress.org/reference/functions/get_query_template/ Reference / Functions / get_query_template()] | ||
[[en:Function Reference/get_query_template]] | [[en:Function Reference/get_query_template]] | ||
[[it:Riferimento funzioni/get_query_template]] | [[it:Riferimento funzioni/get_query_template]] |
2018年6月2日 (土) 12:35時点における最新版
説明
拡張子を含めずファイル名を指定してテンプレートのパスを取得します。locate_template() を利用して、テンプレートの有無を親テーマについてもチェックします。他の get_*_template() 関数を使わずに、より汎用的なテンプレートの取得が行えます。
使い方
<?php get_query_template( $type, $templates ); ?>
パラメータ
- $type
- (文字列) (必須) 拡張子なしのファイル名。
- 初期値: なし
- $templates
- (配列) (オプション) テンプレート候補のリスト。
- 初期値: array()
戻り値
- (文字列)
- テンプレートファイルへのフルパス。
用例
取得したパスのファイルを読み込むには include() や require() が使えます。
if ( '' != get_query_template( '404' ) ) include( get_query_template( '404' ) );
以下のコードでも実現できます。
if ( '' != get_404_template() ) include( get_404_template() );
参考
- $templates が空の場合、{$type}.php を探します。
- 動的なフィルター '{$type}_template_hierarchy' を $templates に適用します。
- locate_template() でテンプレートファイルを特定した後、動的なフィルター '{$type}_template' を適用します。
変更履歴
新規導入: 1.5.0
ソースファイル
get_query_template() は wp-includes/template.php
にあります。
関連項目
関数リファレンス、テンプレートタグ目次もご覧ください。