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. 最基础的Hash

    type thash=^node; node=record state:longint; next:thash; end; var a,i:longint; p:thash; hash:..]of t ...

  2. 【Permutations】cpp

    题目: Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the fo ...

  3. 重读《Struts In Action》

    Figure   1.1. The Java Servlet API exposes the HTTP client/server protocol to the Java   platform. S ...

  4. mongo的insert和save比较

    insert仅仅是插入文档到集合中,如果记录不存在则插入,如果记录存在则忽略 save是在文档不存在时插入,存在时则是更新 下面代码不是为了演示insert和save的: foreach ($mens ...

  5. .NET Framework 4.5、4.5.1 和 4.5.2 中的新增功能

    .NET Framework 4.5.4.5.1 和 4.5.2 中的新增功能 https://msdn.microsoft.com/zh-cn/library/ms171868.aspx

  6. Android 动态Tab分页效果实现

    当前项目使用的是TabHost+Activity进行分页,目前要做个报表功能,需要在一个Tab页内进行Activity的切换.比方说我有4个Tab页分别为Tab1,Tab2,Tab3,Tab4,现在的 ...

  7. 深入理解jQuery中live与bind方法的区别

    本篇文章主要是对jQuery中live与bind方法的区别进行了详细的分析介绍,需要的朋友可以过来参考下,希望对大家有所帮助 注意如果是通过jq添加的层和对象一定要用live(),用其他的都不起作用 ...

  8. JS 学习笔记--6---日期和时间

    在日期和时间这一块的学习中发现,其实和其他大部分的高级语言中时间和日期的操作差不多,没什么特别的,但是要注意的就是 ECMAScript中规定的一些方法在各大浏览器中的实现方式是不一样的,也就是说存在 ...

  9. 2014_acmicpc_shanghai_google

    I http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84975#problem/I 题意:我方有n个士兵,敌方有m个士兵,每个士兵有攻击力和 ...

  10. [Shoi2007]Bookcase 书柜的尺寸 dp

    这道dp算是同类型dp中比较难的了,主要难点在于设置状态上: 如果像平时那样设置,必定爆空间没商量: 下面是一种思路: 先把输入进来的数据按h从大到小排序,这样就可以大大减少状态数, 然后设f[i][ ...