- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
「クラスリファレンス/WP Theme」の版間の差分
提供: WordPress Codex 日本語版
(en:Class Reference/WP Theme 18:07, 9 November 2017 Tazotodua 版を流し込み。) |
(プロパティ節まで訳しました。) |
||
1行目: | 1行目: | ||
− | {{NeedTrans}} | + | {{NeedTrans|[[#Methods|メソッド]]節以降が}} |
− | == | + | == WP_Theme の役割<span id="Role_of_WP_Theme"></span> == |
− | + | ||
− | + | WP_Theme は {{Trac|wp-includes/class-wp-theme.php}} にて定義されているクラスで、開発者がテーマを扱うインターフェイスを提供します。 | |
− | + | ||
− | === | + | == メソッドとプロパティ<span id="Methods_and_Properties"></span> == |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | === Methods === | + | これは <tt>WP_Theme</tt> の正式なドキュメントです。 |
− | ; errors() : Returns [[ | + | |
+ | '''注意:''' プロパティを直接書き換えず、代わりにメソッドを使ってプロパティを扱ってください。 | ||
+ | |||
+ | == プロパティ<span id="Properties"></span> == | ||
+ | |||
+ | ; Name : WordPress テーマ オブジェクト | ||
+ | ; ThemeURI : テーマの web ページの URI | ||
+ | ; Description : テーマの説明 | ||
+ | ; Author : テーマの作者 | ||
+ | ; AuthorURI : テーマ作者の web サイト | ||
+ | ; Version : テーマのバージョン | ||
+ | ; Template : (オプション — 子テーマで使用) 親テーマのフォルダー名 | ||
+ | ; Status : テーマが公開されているか | ||
+ | ; Tags : テーマを説明するタグ | ||
+ | ; TextDomain : 翻訳のためにテーマ内で使われるテキストドメイン | ||
+ | ; DomainPath : テーマの翻訳ファイルのパス | ||
+ | |||
+ | === メソッド<span id="Methods"></span> === | ||
+ | |||
+ | ; errors() : Returns [[クラスリファレンス/WP_Error|WP_Error]] オブジェクト with error information. If there isn't any error information then it returns false | ||
; exists() : Boolean for if the theme exists | ; exists() : Boolean for if the theme exists | ||
− | ; parent() : Returns parent WP_Theme | + | ; parent() : Returns parent WP_Theme オブジェクト or false if there is no parent theme |
; cache_delete() : Clears the cache for the theme | ; cache_delete() : Clears the cache for the theme | ||
− | ==== | + | ==== ヘッダー用メソッド<span id="Header_Methods"></span> ==== |
− | ; get( $header ) : Used to get a sanitized but unformatted theme header. Use the [[ | + | |
+ | ; get( $header ) : Used to get a sanitized but unformatted theme header. Use the [[関数リファレンス/get_template|get_template()]] method to find the template, not the 'Template' header. Returns string on success and false on failure | ||
; display ( $header, $markup, $translate ) : Gets the theme header then formats and translates it for display. | ; display ( $header, $markup, $translate ) : Gets the theme header then formats and translates it for display. | ||
− | ==== | + | ==== パスと URL 用のメソッド<span id="Path_and_URL_Methods"></span> ==== |
+ | |||
; 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_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_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. | ||
40行目: | 48行目: | ||
; 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_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. | ||
− | ==== | + | ==== ファイルとイメージ<span id="Files_and_Images"></span> ==== |
+ | |||
; 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_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_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. | ; get_page_templates() : Returns an array of page templates, keyed by the filename, with the value of the translated header name. | ||
− | ==== | + | ==== 権限用のメソッド<span id="Permission_Methods"></span> ==== |
+ | |||
; is_allowed() : Boolean value for if a theme is allowed for the network. Always returns true if called on a single site. | ; 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( $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 ). | ||
51行目: | 61行目: | ||
; get_allowed_on_site( $blog_id ) : Returns an array of theme names that are allowed on the site. | ; get_allowed_on_site( $blog_id ) : Returns an array of theme names that are allowed on the site. | ||
− | ==== Sorting ==== | + | ==== 並べ替え<span id="Sorting"></span> ==== |
+ | |||
; sort_by_name( $themes ) : Sorts themes by name | ; sort_by_name( $themes ) : Sorts themes by name | ||
== 用例<span id="Examples"></span> == | == 用例<span id="Examples"></span> == | ||
− | === | + | === カスタムページテンプレートを取得<span id="Get_Custom_Page_Templates"></span> === |
− | The following code snippets return all the custom [[ | + | |
+ | 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). | ||
<pre> | <pre> | ||
80行目: | 92行目: | ||
== 変更履歴<span id="Change_Log"></span> == | == 変更履歴<span id="Change_Log"></span> == | ||
− | + | 新規導入 : [[Version 3.4|3.4.0]] | |
== ソースファイル<span id="Source_File"></span> == | == ソースファイル<span id="Source_File"></span> == | ||
− | <tt>WP_Theme</tt> | + | <tt>WP_Theme</tt> は {{Trac|wp-includes/class-wp-theme.php}} にあります。 |
== 関連項目<span id="Related"></span> == | == 関連項目<span id="Related"></span> == |
2018年6月3日 (日) 23:59時点における版
このページ「クラスリファレンス/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()
- Returns WP_Error オブジェクト with error information. If there isn't any error information then it returns false
- exists()
- Boolean for if the theme exists
- parent()
- Returns parent WP_Theme オブジェクト or false if there is no parent theme
- cache_delete()
- Clears the cache for the theme
ヘッダー用メソッド
- get( $header )
- Used to get a sanitized but unformatted theme header. Use the get_template() method to find the template, not the 'Template' header. Returns string on success and false on failure
- display ( $header, $markup, $translate )
- Gets the theme header then formats and translates it for display.
パスと 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
にあります。