wordpress安装后的文件目录如下:

其中的主要目录和文件用途介绍如下:

wp-admin:用于进行博客后台设置的功能目录

wp-content: wordpress的 主题,插件和本地化的存储目录

wp-include: wordpress一些类和公共函数文件的存放目录。

根目录下的index.php是大部分wordpress功能的入口模块。

大概看了一下入口代码的调用关系,画图如下:

上图中只绘制了主要的流程。流程主要分为三个部分,分别是全局的初始化,数据读取和模板渲染。

wp-load.php中进行了一串的函数调用,定了了全局变量,引用必要的php文件。

wp()函数主要调用wp-include/class-wp.php中的类方法,实现不同请求的预处理,加载对应的数据到全局对象中,以后后续的模板页面来展示。

template-loader.php中实现按照不同的url参数,来加载不同的模板。

先熟悉下模板的加载流程:

$template = false;
if ( is_404() && $template = get_404_template() ) :
elseif ( is_search() && $template = get_search_template() ) :
elseif ( is_front_page() && $template = get_front_page_template() ) :
elseif ( is_home() && $template = get_home_template() ) :
elseif ( is_post_type_archive() && $template = get_post_type_archive_template() ) :
elseif ( is_tax() && $template = get_taxonomy_template() ) :
elseif ( is_attachment() && $template = get_attachment_template() ) :
remove_filter('the_content', 'prepend_attachment');
elseif ( is_single() && $template = get_single_template() ) :
elseif ( is_page() && $template = get_page_template() ) :
elseif ( is_category() && $template = get_category_template() ) :
elseif ( is_tag() && $template = get_tag_template() ) :
elseif ( is_author() && $template = get_author_template() ) :
elseif ( is_date() && $template = get_date_template() ) :
elseif ( is_archive() && $template = get_archive_template() ) :
elseif ( is_comments_popup() && $template = get_comments_popup_template() ) :
elseif ( is_paged() && $template = get_paged_template() ) :
else :
$template = get_index_template();
endif; if ( $template = apply_filters( 'template_include', $template ) )
include( $template );
return;

以上代码很清楚能看出根据不同的页面类型,加载不同的模板php文件。上面代码中的get_home_template函数定义如下:

function get_home_template() {
$templates = array( 'home.php', 'index.php' );
return get_query_template( 'home', $templates );
}

  上面代码可以看出默认的home页面会加载的页面是home.php或者index.php文件.

get_query_template能够获取到指定类型的模板文件路径。

function get_query_template( $type, $templates = array() ) {
$type = preg_replace( '|[^a-z0-9-]+|', '', $type ); if ( empty( $templates ) )
$templates = array("{$type}.php"); $template = locate_template( $templates );
/**
* Filter the path of the queried template by type.
*
* The dynamic portion of the hook name, `$type`, refers to the filename
* -- minus the extension -- of the file to load. This hook also applies
* to various types of files loaded as part of the Template Hierarchy.
*
* @since 1.5.0
*
* @param string $template Path to the template. See {@see locate_template()}.
*/
return apply_filters( "{$type}_template", $template );
}

  locate_template函数判断出对应的模板文件是否存在,如果存在,$load为真时加载对应的模板文件,否则仅仅是返回模板文件的路径。

function locate_template($template_names, $load = false, $require_once = true ) {
$located = '';
foreach ( (array) $template_names as $template_name ) {
if ( !$template_name )
continue;
if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {
$located = STYLESHEETPATH . '/' . $template_name;
break;
} elseif ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {
$located = TEMPLATEPATH . '/' . $template_name;
break;
}
} if ( $load && '' != $located )
load_template( $located, $require_once ); return $located;
}

 上面的几个函数主要是选择哪个模板,模板路径如何得来,加载的过程展示。有了这些代码的基础,我们对url的不同参数,应该出什么模板,对应的模板应该找什么php文件,就很清楚了。后面我们讲到模板的编写时候,也会有对应的模板加载相关的内容。

wordpress学习二:源码目录结构和启动流程的更多相关文章

  1. Vue2.x源码学习笔记-源码目录结构整理

    先从github上下载或者clone一个vue分支项目 https://github.com/vuejs/vue 查看下目录结果 先列出一些目录 Vue |— build 打包相关的配置文件,其中最重 ...

  2. 【安卓本卓】Android系统源码篇之(一)源码获取、源码目录结构及源码阅读工具简介

    前言        古人常说,“熟读唐诗三百首,不会作诗也会吟”,说明了大量阅读诗歌名篇对学习作诗有非常大的帮助.做开发也一样,Android源码是全世界最优秀的Android工程师编写的代码,也是A ...

  3. Linux基础系列—Linux内核源码目录结构

    /** ****************************************************************************** * @author    暴走的小 ...

  4. chromium浏览器开发系列第三篇:chromium源码目录结构

    上两篇介绍了下载源码和编译源码,这次主要介绍chromium的源码目录结构,我也是通过源码和官网结合来跟大家说,如果有说的不准确的,欢迎交流. 另外,官网的不一定准确,他们其实也很懒,所以最主要还是靠 ...

  5. InfluxDB源码目录结构解析

    操作系统 : CentOS7.3.1611_x64 go语言版本:1.8.3 linux/amd64 InfluxDB版本:1.1.0 influxdata主目录结构 [root@localhost ...

  6. (转)android系统架构及源码目录结构

    转自:http://blog.csdn.net/finewind/article/details/46324507 1. Android系统架构: android系统架构采用了分层架构的思想,如下图所 ...

  7. (3.1)mysql基础深入——mysql二进制与源码目录结构介绍

    (3.1)mysql基础深入——mysql二进制与源码目录结构介绍 关键字:二进制目录结构,源码目录结构(编译安装目录结构) 1.二进制安装程序目录结构 [1] BIN -- mysql的可执行文件( ...

  8. Locust源码目录结构及模块作用

    Locust源码目录结构及模块作用如下: 参考文章:https://blog.csdn.net/biheyu828/article/details/84031942

  9. Source Code Structure - Python 源码目录结构

    Source Code Structure - Python 源码目录结构 Include 目录包含了 Python 提供的所有头文件, 如果用户需要用 C 或 C++ 编写自定义模块扩展 Pytho ...

随机推荐

  1. JAVA类与对象(九)------多态

    多态是同一个行为具有多个不同表现形式或形态的能力.多态性是对象多种表现形式的体现. 多态存在的三个必要条件: 继承 重写 父类引用指向子类对象 例:Parent p = new Child(); 当使 ...

  2. 文本阴影text-shadow

    文本阴影text-shadow text-shadow可以用来设置文本的阴影效果. 语法: text-shadow: X-Offset Y-Offset blur color; X-Offset:表示 ...

  3. html textarea换行和dom换行

    从事开发已经两年多了,但是还是不会发现问题找原因,可能是自己一直在学校养成的习惯吧,不过最近在葛经理的带领下开始学会找原因了,而且发现自己变得更成熟了. 现在讲讲textarea和dom的换行吧,我们 ...

  4. Gentoo 网络接口配置文件说明

    裁剪的Gentoo系统,仅供公司内部使用! [作为备份档案] 网络接口配置:/etc/conf.d/net #设置静态IPconfig_eth0="192.168.1.x/24" ...

  5. 【Binary Tree Zigzag Level Order Traversal】cpp

    题目: Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from lef ...

  6. Readhat Linux5.5 安装SVNService(经验总结)

    Subversion独立服务和与apache整合服务. 一 .Svn独立服务安装 操作系统: Redhat Linux5.5 安装包获取: 下载 http://subversion.tigris.or ...

  7. 在ubuntu上搭建reviewboard

    review board 2.0.5 ubuntu ubuntu-12.04.1-desktop-amd64 基本上基于这个教程:http://alephnullplex.appspot.com/bl ...

  8. 【python】正则表达式

    参考资料:http://deerchao.net/tutorials/regex/regex.htm 1.正则表达式基础 2.python 正则表达式 1.正则表达式基础 元字符: 其他语法: (1) ...

  9. SPOJ 057 Supernumbers in a permutation

    原题链接:http://www.spoj.com/problems/SUPPER/ 这道题n<=200000,那么确定为nlogn的算法,再定位到求LIS的O(nlogn)的算法. 对于每个a[ ...

  10. Kali-linux安装之后的简单设置

    1.更新软件源:修改sources.list文件:leafpad /etc/apt/sources.list然后选择添加以下适合自己较快的源(可自由选择,不一定要全部): #官方源deb http:/ ...