首先从wordpress程序index.php入手:
复制代码代码如下:
define('WP_USE_THEMES', true);/** Loads the WordPress Environment and Template */require( dirname( __FILE__ ) . '/wp-blog-header.php' );index.php加载了wp-blog-header.php文件,再打开看看:
复制代码代码如下:
if ( !isSet($wp_did_header) ) {$wp_did_header = true;require_once( dirname(__FILE__) . '/wp-load.php' );wp();require_once( ABSPATH . WPINC . '/template-loader.php' );}再打开wp-load.php:
复制代码代码如下:
if ( file_exists( ABSPATH . 'wp-config.php') ) {/** The config file resides in ABSPATH */require_once( ABSPATH . 'wp-config.php' );} elseif ( file_exists( dirname(ABSPATH) . '/wp-config.php' ) && ! file_exists( dirname(ABSPATH) . '/wp-settings.php' ) ) {/** The config file resides one level above ABSPATH but is not part of Another install */require_once( dirname(ABSPATH) . '/wp-config.php' );} else {……}它加载了配置文件config.php,打开config.php看看:
复制代码代码如下:
/* 好了!请不要再继续编辑。请保存本文件。使用愉快! *//** WordPress目录的绝对路径。 */if ( !defined('ABSPATH') )define('ABSPATH', dirname(__FILE__) . '/');/** 设置WordPress变量和包含文件。 */require_once(ABSPATH . 'wp-settings.php');找到最下面几行,它加载了wp-settings.php文件,打开看看:
复制代码
代码如下:
define( 'WPINC', 'wp-includes' );// Include files required for initialization.require( ABSPATH . WPINC . '/load.php' );require( ABSPATH . WPINC . '/default-constants.php' );require( ABSPATH . WPINC . '/version.php' );它加载了load.php文件,打开load.php文件其中有个函数:
复制代码代码如下:
function require_wp_db() {global $wpdb;require_once( ABSPATH . WPINC . '/wp-db.php' );if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )require_once( WP_CONTENT_DIR . '/db.php' );if ( isset( $wpdb ) )return;$wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );}并且在该文件(wp-settings.php)下面调用了require_wp_db()方法:
复制代码代码如下:
// Include the wpdb class and, if present, a db.php>于是找到了,经过层层加载文件和调用,在这里进行了$wpdb这个变量的全局定义。
全局变量 WordPress自定义多个边栏的方法 wordpress中强大的调用文章函数query posts














发表评论