wp() 函数位于 wp-includes/functions.php 中
/** * Set up the WordPress query. * * @since 2.0.0 * * @global WP $wp_locale * @global WP_Query $wp_query * @global WP_Query $wp_the_query * * @param string|array $query_vars Default WP_Query arguments. */ function wp( $query_vars = '' ) { global $wp, $wp_query, $wp_the_query; $wp->main( $query_vars ); if ( !isset($wp_the_query) ) $wp_the_query = $wp_query; }
这个函数用来设置 WordPress 查询,参数是 $query_vars,可选,默认的 WP_Query 参数。
该函数不返回任何值,它定义了三个全局变量:
- 使用全局变量:(对象)$wp
- 使用全局变量:(对象)$$wp_query
- 使用全局变量:(对象)$wp_the_query
wp() 函数执行了 WP 类的成员方法 main(),WP 类位于 wp-includes/classes.php 中。
main()的内容:
/** * Sets up all of the variables required by the WordPress environment. * * The action {@see 'wp'} has one parameter that references the WP object. It * allows for accessing the properties and methods to further manipulate the * object. * * @since 2.0.0 * @access public * * @param string|array $query_args Passed to parse_request(). */ public function main($query_args = '') { $this->init();// 初始化,获取当前用户信息 $this->parse_request($query_args);// 解析请求 $this->send_headers();// 发送头信息 $this->query_posts();// 查询日志 $this->handle_404();// 操作404(URL地址不存在) $this->register_globals();// 注册全局变量 /** * Fires once the WordPress environment has been set up. * * @since 2.1.0 * * @param WP &$this Current WordPress environment instance (passed by reference). */ do_action_ref_array( 'wp', array( &$this ) ); } }
做完这些操作还是会回到 wp-blog-header.php,
包含 wp-includes/template-loader.php 来加载模板并显示,
日志显示日志,页面显示页面,404显示404
这里还不明白,需要继续学习QAQ