index.php 「フロントファイル」
そろそろwordpressの拡張、独自プラグインを作成したいと思ってきたので、まずはwordpressの構造を解析してみようと思います。
※wordpress2.71で解析しています。

wordpressは、まず「index.php」を読み込みます。このファイルを開くとコメントで次のように書かれています。
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
【訳】
「wordpressアプリケーションのフロントです。このファイルはただテーマを呼んで実行する「wp-blog-header.php」をロードするだけです。
「フロント」と説明されています。ホテルなどのフロントと同じで「入り口」という意味です。wordpressの入り口ファイルなので一番最初に読まれます。
/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');
上記説明に書かれている通り、「wp-blog-header.php」ファイルを読み込んでいました。
別に次のようなコードがありました。
/**
* Tells WordPress to load the WordPress theme and output it.
*/
define('WP_USE_THEMES', true);
「WP_USE_THEMES」をいう定数を設定しています。この定数は何に使うのか調べてみました。

wordpress内を「WP_USE_THEMES」で検索をかけると、3つのファイルがひっかかりました。
「index.php」はこの定数を設定しているファイルです(今みているファイル)。
「upgrade.php」には、「if (strpos($index, 'WP_USE_THEMES') !== false) 」と記述されています。定数を使うのではなく、この文字が含まれているかどうかみているだけのようなので、ここは特に関係なさそうです。
if ( defined('WP_USE_THEMES') && constant('WP_USE_THEMES') ) {
①WP_USE_THEMESが定義されている
且つ constant('WP_USE_THEMES') が ture の場合の処理
else{
②それ以外の処理
}
「WP_USE_THEMES'」の定数値が 「ture」 か 「false」 により読み込めるテンプレートの種類が異なるようです。
| テンプレート | true | false |
| is_robots() | 〇 | 〇 |
| is_feed() | 〇 | 〇 |
| is_trackback() | 〇 | 〇 |
| is_404() | 〇 | × |
| is_search() | 〇 | × |
| is_tax() | 〇 | × |
| is_home() | 〇 | × |
| is_attachment() | 〇 | × |
| is_single() | 〇 | × |
| is_page() | 〇 | × |
| is_category() | 〇 | × |
| is_tag() | 〇 | × |
| is_author() | 〇 | × |
| is_date() | 〇 | × |
| is_archive() | 〇 | × |
| is_comments_popup() | 〇 | × |
| is_paged() | 〇 | × |
| index.php | 〇 | × |


2009 年 5 月 30 日 9:40 PM
[...] フロントファイル「index.php」 [...]