- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
関数リファレンス/get template part
このページ「関数リファレンス/get template part」は未翻訳です。和訳や日本語情報を加筆してくださる協力者を求めています。
タグ一覧: テンプレートタグ | インクルードタグ | 条件分岐タグ | その他の関数 | Code Reference
使い方: テンプレートタグ入門 | パラメータの渡し方 | 初心者の方へ | その他のテーマ関連資料
目次
Description
Load a template part into a template (other than header, sidebar, footer). Makes it easy for a theme to reuse sections of code in a easy to overload way for child themes.
Includes the named template part for a theme or if a name is specified then a specialized part will be included. If the theme contains no {slug}.php file then no template will be included.
For the parameter, if the file is called "{slug}-{name}.php".
Usage
<?php get_template_part( $slug, $name ) ?>
Parameters
- $slug
- (string) (必須) The slug name for the generic template.
- 初期値: なし
- $name
- (string) (optional) The name of the specialized template.
- 初期値: なし
Examples
Using loop.php in child themes
Assuming the theme folder is wp-content/themes, that the parent theme is twentyten, and the child theme is twentytenchild, this example will do a PHP require() for the named files in this order:
- wp-content/themes/twentytenchild/loop-index.php
- wp-content/themes/twentytenchild/loop.php
- wp-content/themes/twentyten/loop-index.php
- wp-content/themes/twentyten/loop.php
<?php get_template_part( 'loop', 'index' ); ?>
Adding a navigation bar to theme using a gereric nav.php template file:
<?php get_template_part( 'nav' ); // Navigation bar (nav.php) ?> <?php get_template_part( 'nav', '2' ); // Navigation bar #2 (nav-2.php) ?> <?php get_template_part( 'nav', 'single' ); // Navigation bar to use in single pages (nav-single.php) ?>
source: wp-tricks.co.il - using get_template_part() to create generic navigation bar
Notes
- Uses: locate_template()/en
- Uses: do_action()/en Calls 'get_template_part{$slug}' action.
Change Log
- Since: 3.0
Source File
get_template_part() is located in wp-includes/general-template.php
.
最新英語版: WordPress Codex » Function Reference/get_template_part (最新版との差分)
Related
インクルードタグ: get_header(), get_footer(), get_sidebar(), get_template_part(), get_search_form(), comments_template()