- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
「クラスリファレンス/WP Theme」の版間の差分
提供: WordPress Codex 日本語版
細 (見出しレベルを修正。) |
(→パスと URL 用のメソッド: まで翻訳。他に ゆらぎ 修正。) |
||
1行目: | 1行目: | ||
− | {{NeedTrans|[[# | + | {{NeedTrans|[[#Files_and_Images|ファイルとイメージ]]節以降が}} |
== WP_Theme の役割<span id="Role_of_WP_Theme"></span> == | == WP_Theme の役割<span id="Role_of_WP_Theme"></span> == | ||
19行目: | 19行目: | ||
; AuthorURI : テーマ作者の web サイト | ; AuthorURI : テーマ作者の web サイト | ||
; Version : テーマのバージョン | ; Version : テーマのバージョン | ||
− | ; Template : (オプション — 子テーマで使用) | + | ; Template : (オプション — 子テーマで使用) 親テーマのフォルダ名 |
; Status : テーマが公開されているか | ; Status : テーマが公開されているか | ||
; Tags : テーマを説明するタグ | ; Tags : テーマを説明するタグ | ||
39行目: | 39行目: | ||
==== パスと URL 用のメソッド<span id="Path_and_URL_Methods"></span> ==== | ==== パスと URL 用のメソッド<span id="Path_and_URL_Methods"></span> ==== | ||
− | ; get_stylesheet() : | + | ; get_stylesheet() : テーマのルートにある <tt>"stylesheet"</tt> ファイルのディレクトリ名を文字列として返します。子テーマのときは子テーマのディレクトリです。 |
− | ; get_template() : | + | ; get_template() : テーマの <tt>"template"</tt> ファイルのディレクトリ名を文字列として返します。子テーマのときは''親テーマ''のディレクトリです。 |
− | ; get_stylesheet_directory() : | + | ; get_stylesheet_directory() : テーマのスタイルシートファイルの絶対パスを文字列として返します。子テーマのときは子テーマのファイルのパスです。 |
− | ; get_template_directory() : | + | ; get_template_directory() : テーマのテンプレートファイルの絶対パスを文字列として返します。子テーマのときは''親テーマ''のファイルのパスです。 |
− | ; get_stylesheet_directory_uri() : | + | ; get_stylesheet_directory_uri() : テーマのスタイルシートファイルの URL を文字列として返します。子テーマのときは子テーマのファイルの URL です。 |
− | ; get_template_directory_uri() : | + | ; get_template_directory_uri() : テーマのテンプレートファイルの URL を文字列として返します。子テーマのときは''親テーマ''のファイルの URL です。 |
− | ; get_theme_root() : | + | ; get_theme_root() : テーマルート(すべてのテーマが入る)のディレクトリのパスを文字列として返します。普通は <tt>wp-content/themes</tt> フォルダの絶対パスです。 |
− | ; get_theme_root_uri() : | + | ; get_theme_root_uri() : テーマルートのディレクトリの URL を文字列として返します。普通は <tt>wp-content/themes</tt> フォルダの URL です。 |
==== ファイルとイメージ<span id="Files_and_Images"></span> ==== | ==== ファイルとイメージ<span id="Files_and_Images"></span> ==== |
2018年6月9日 (土) 09:44時点における版
このページ「クラスリファレンス/WP Theme」はファイルとイメージ節以降が未翻訳です。和訳や日本語情報を加筆してくださる協力者を求めています。
目次
WP_Theme の役割
WP_Theme は wp-includes/class-wp-theme.php
にて定義されているクラスで、開発者がテーマを扱うインターフェイスを提供します。
メソッドとプロパティ
これは WP_Theme の正式なドキュメントです。
注意: プロパティを直接書き換えず、代わりにメソッドを使ってプロパティを扱ってください。
プロパティ
- Name
- WordPress テーマ オブジェクト
- ThemeURI
- テーマの web ページの URI
- Description
- テーマの説明
- Author
- テーマの作者
- AuthorURI
- テーマ作者の web サイト
- Version
- テーマのバージョン
- Template
- (オプション — 子テーマで使用) 親テーマのフォルダ名
- Status
- テーマが公開されているか
- Tags
- テーマを説明するタグ
- TextDomain
- 翻訳のためにテーマ内で使われるテキストドメイン
- DomainPath
- テーマの翻訳ファイルのパス
メソッド
- errors()
- エラー情報を持つ WP_Error オブジェクトを返します。エラー情報がないとき false を返します。
- exists()
- テーマが存在するとき true を返します。
- parent()
- 親テーマの WP_Theme オブジェクトを返します。親テーマがないとき false を返します。
- cache_delete()
- テーマのキャッシュを消去します。
ヘッダー用メソッド
- get( $header )
- 整形する前のテーマヘッダーを無害化して返します。テンプレートを探すには 'Template' ヘッダーではなく get_template() メソッドを使ってください。成功すると文字列、失敗すると false を返します。
- display ( $header, $markup, $translate )
- テーマヘッダーを取得し整形することにより、表示用に変換します。
パスと URL 用のメソッド
- get_stylesheet()
- テーマのルートにある "stylesheet" ファイルのディレクトリ名を文字列として返します。子テーマのときは子テーマのディレクトリです。
- get_template()
- テーマの "template" ファイルのディレクトリ名を文字列として返します。子テーマのときは親テーマのディレクトリです。
- get_stylesheet_directory()
- テーマのスタイルシートファイルの絶対パスを文字列として返します。子テーマのときは子テーマのファイルのパスです。
- get_template_directory()
- テーマのテンプレートファイルの絶対パスを文字列として返します。子テーマのときは親テーマのファイルのパスです。
- get_stylesheet_directory_uri()
- テーマのスタイルシートファイルの URL を文字列として返します。子テーマのときは子テーマのファイルの URL です。
- get_template_directory_uri()
- テーマのテンプレートファイルの URL を文字列として返します。子テーマのときは親テーマのファイルの URL です。
- get_theme_root()
- テーマルート(すべてのテーマが入る)のディレクトリのパスを文字列として返します。普通は wp-content/themes フォルダの絶対パスです。
- get_theme_root_uri()
- テーマルートのディレクトリの URL を文字列として返します。普通は wp-content/themes フォルダの URL です。
ファイルとイメージ
- get_screenshot( $uri )
- Returns the URL to the screenshot image for the theme. The $uri parameter determines the type of url to return. Passing 'relative' returns a relative URL otherwise it defaults to an absolute URL.
- get_files( $type, $depth, $search_parent )
- Returns an array of files in the theme's directory.
- get_page_templates()
- Returns an array of page templates, keyed by the filename, with the value of the translated header name.
権限用のメソッド
- is_allowed()
- Boolean value for if a theme is allowed for the network. Always returns true if called on a single site.
- get_allowed( $blog_id )
- Returns an array of theme names that are allowed on the site or network. The $blog_id defaults to current blog. This method calls both get_allowed_on_network() and get_allowed_on_site( $blog_id ).
- get_allowed_on_network ()
- Returns an array of theme names that are allowed on the network.
- get_allowed_on_site( $blog_id )
- Returns an array of theme names that are allowed on the site.
並べ替え
- sort_by_name( $themes )
- Sorts themes by name
用例
カスタムページテンプレートを取得
The following code snippets return all the custom ページテンプレート available to the currently activated theme as an array. Each array item has a key of the Template Name and value of the filename (or folder-name and filename for custom page templates stored in a theme's subdirectory).
<?php $templates = wp_get_theme()->get_page_templates(); foreach ( $templates as $template_name => $template_filename ) { echo "$template_name ($template_filename)<br />"; } ?>
<?php print_r( wp_get_theme()->get_page_templates() ); ?> // Outputs: Array ( [My Custom Page Template] => my-custom-page.php [A Second Custom Page] => my-page-templates/my-second-page.php )
変更履歴
新規導入 : 3.4.0
ソースファイル
WP_Theme は wp-includes/class-wp-theme.php
にあります。