- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
「関数リファレンス/get theme root」の版間の差分
提供: WordPress Codex 日本語版
< 関数リファレンス
(各章の名前と、戻り値まで翻訳完了。) |
細 (→関連項目) |
||
(他の1人の利用者による、間の1版が非表示) | |||
22行目: | 22行目: | ||
== 使用例 == | == 使用例 == | ||
</div> | </div> | ||
− | <!-- | + | <!-- クリエイティブな事例を載せてください。外部リンクも大歓迎です --> |
− | = | + | <div id="Number of Subdirectories in Themes Directory"> |
− | + | === テーマディレクトリ内のサブディレクトリ数 === | |
− | + | </div> | |
+ | テーマディレクトリ内のサブディレクトリ数を引用する関数です。これは WordPress が認識していると一致している必要はありません。 | ||
<pre><?php | <pre><?php | ||
31行目: | 32行目: | ||
$theme_root = get_theme_root(); | $theme_root = get_theme_root(); | ||
$files_array = glob("$theme_root/*", GLOB_ONLYDIR); | $files_array = glob("$theme_root/*", GLOB_ONLYDIR); | ||
− | echo " | + | echo . $theme_root " ディレクトリには" . count($files_array) . "個のサブディレクトリがあります。"; |
} | } | ||
?></pre> | ?></pre> | ||
− | + | 出力例: | |
− | <div style="border:1px solid blue; margin: 20px 0; padding:20px"> | + | <div style="border:1px solid blue; margin: 20px 0; padding:20px"> /home/user/public_html/wp-content/themes ディレクトリには 5 個のサブディレクトリがあります。</div> |
<div id="Notes"> | <div id="Notes"> | ||
== 注 == | == 注 == | ||
</div> | </div> | ||
− | * | + | * 引用されたパスに [[Plugin API/Filter Reference/theme_root|theme_root]] フィルターを適用させるために、 [[Function Reference/apply_filters|<tt>apply_filters()</tt>]] を用います。 |
<div id="Change Log"> | <div id="Change Log"> | ||
64行目: | 65行目: | ||
{{Tag Footer}} | {{Tag Footer}} | ||
− | |||
− | |||
− |
2015年5月18日 (月) 09:17時点における最新版
テーマディレクトリの絶対パスを取得します。この時、最後のスラッシュは記載されません。
使用法
<?php get_theme_root(); ?>
パラメーター
- $stylesheet_or_template
- (string) (必須) テーマのスタイルシートまたはテンプレート名
- 初期値: なし
戻り値
- (string)
- テーマディレクトリの絶対パス。ただし、最後のスラッシュは記載されません。
使用例
テーマディレクトリ内のサブディレクトリ数
テーマディレクトリ内のサブディレクトリ数を引用する関数です。これは WordPress が認識していると一致している必要はありません。
<?php function display_themes_subdirs_count_info() $theme_root = get_theme_root(); $files_array = glob("$theme_root/*", GLOB_ONLYDIR); echo . $theme_root " ディレクトリには" . count($files_array) . "個のサブディレクトリがあります。"; } ?>
出力例:
/home/user/public_html/wp-content/themes ディレクトリには 5 個のサブディレクトリがあります。
注
- 引用されたパスに theme_root フィルターを適用させるために、 apply_filters() を用います。
改訂履歴
1.5.0 にて導入されました。
ソースファイル
get_theme_root() は wp-includes/theme.php
にあります。
関連項目
テーマのパス: get_template(), get_template_directory(), get_template_directory_uri(), get_theme_roots() /en, get_theme_root(), get_theme_root_uri() /en, get_stylesheet() /en, get_stylesheet_uri(), get_stylesheet_directory(), get_stylesheet_directory_uri(), get_bloginfo()
最新英語版: WordPress Codex » Function Reference/get theme root (最新版との差分)
関数リファレンス、テンプレートタグ目次もご覧ください。