Warning: Undefined array key 0 in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 406

Warning: Attempt to read property "parent" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 407

Warning: Attempt to read property "term_id" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 413

Warning: Attempt to read property "cat_name" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 413

【WordPress】テンプレートファイルの呼び出しと利用


Warning: Undefined variable $pre in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 517

Warning: Undefined variable $pre in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 517

Warning: Undefined variable $pre in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 517

Warning: Undefined variable $pre in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/functions.php on line 517
wordpress

サイトにおいて同じ記述を複数個所で使うことがあります。 例えばページャーの記述は全く同じものを複数のアーカイブファイルで使ったりしますよね。

こういった記述はテンプレートファイルとしてひとまとめにして呼び出す形で使います。 そうすれば書き間違いになり難いですし、修正の際にも1箇所修正すれば全てに反映されて便利です。

テンプレートファイルを呼び出す書式

テンプレートファイルは独立したPHPファイルに別途記述して随時呼び出す形で使います。 あらかじめPHPファイルを作り、それをget_template_part関数にて呼び出します。

テンプレートファイルはphpファイルなので、拡張子は不要です。

et_template_part( 'ファイル名' ); 

テンプレートファイルのhoge.phpを呼び出したい場合は以下のようになります。

et_template_part( 'hoge' ); 

テンプレートファイルを引数付きで呼び出す

テンプレートを引数付きで呼び出すことも可能です。 テンプレートファイル「hoge.php」を引数「arg」付きで呼び出し、引数には1を指定します。

テンプレートファイル側で引数を取得してテンプレートファイルで使います。 引数は見出し名として使ったり、判定フラグとして使ったりなど使い方は色々あります。


Warning: Undefined variable $category in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/content.php on line 79

Warning: Attempt to read property "name" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/content.php on line 79

の記事

eyecatch

windows環境でファイルの拡張子を表示させる方法

eyecatch

ウェブサイトの標準カラー16色とウェブセーフカラー216色

eyecatch

CSSで指定したスタイルをHTMLに読み込む方法

eyecatch

WordPressサイトのSEOを向上するプラグイン「All In One SEO Pack」

eyecatch

コメント機能を削除するプラグイン「Disable Comments」

eyecatch

JavaScriptの繰り返し処理


Warning: Undefined variable $category in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/content.php on line 84

Warning: Attempt to read property "count" on null in /home/yatsuba/yatsuba.com/public_html/wp-content/themes/amaru/content.php on line 84
HOME