当サイト、Codex 日本語版は今後積極的な更新は行わない予定です。後継となる新ユーザーマニュアルは、https://ja.wordpress.org/support/ にあります。
万が一、当サイトで重大な問題を発見した際などは、フォーラムや WordSlack #docs チャンネルでお知らせください。</p>
万が一、当サイトで重大な問題を発見した際などは、フォーラムや WordSlack #docs チャンネルでお知らせください。</p>
クラスリファレンス/WP Theme
提供: WordPress Codex 日本語版
このページ「クラスリファレンス/WP Theme」はパスと URL 用のメソッド節以降が未翻訳です。和訳や日本語情報を加筆してくださる協力者を求めています。
目次
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()
- Returns a string with the directory name of the theme's "stylesheet" files, inside the theme root. If this is a child theme it is the directory from the child theme.
- get_template()
- Returns a string with the directory name of the theme's "template" file. If this is a child theme it is the directory from the parent theme.
- get_stylesheet_directory()
- Returns a string with the absolute path to a theme's stylesheet files. If the theme is a child theme, the path will be to the child theme files.
- get_template_directory()
- Returns a string with the absolute path to a theme's template files. If the theme is a child theme, the path will be to the parent theme files.
- get_stylesheet_directory_uri()
- Returns a string with the URL to the theme's stylesheet files. If the theme is a child theme, the URL will be to the child theme files.
- get_template_directory_uri()
- Returns a string with the URL to the theme's template files. If the theme is a child theme, the URL will be to the parent theme files.
- get_theme_root()
- Returns a string with the path to the directory of the theme root. This is typically the absolute path to the wp-content/themes folder.
- get_theme_root_uri()
- Returns a string with the URL to the directory of the theme root. This is typically the absolute URL to the wp-content/themes folder.
ファイルとイメージ
- 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
にあります。