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. CoolShell Puzzle攻略[更新隐藏剧情]

    CoolShell博主陈皓做了一个在线的puzzle很有意思,链接在这里,这里记录一下解题的一些步骤. Puzzle 0 ++++++++[>+>++>+++>++++> ...

  2. Lua利用cjson读写json示例分享

    本文结合本人的实际使用经验和代码示例,介绍如何在Lua中对json进行encode和decode,需要的朋友可以参考下 我这里采用的是Lua CJson库,是一个高性能的JSON解析器和编码器,其性能 ...

  3. Team Homework #2 Decide the roles of each team member ——IloveSE

    大家好,我们是IloveSEers! 徐姗,我是一个性格开朗,但却认为计算机比较枯燥的女生.经过两年的学习,自己的编程能力,并不是很强,在这方便还需多多练习.对于软件工程这门课,我充满期待,因为我不仅 ...

  4. 拓展Jquery对象,实现Post提交并跳转

    $.extend({ StandardPost:function(url,args){ var body = $(document.body), form = $("<form met ...

  5. mono for andorid 引用外部的dll问题

    这几天玩mono for android 心想,咱c#终于可以开发移动应用了,心里那个美啊------------ 先开发个什么呢,想起来前几天看到微博里一个用姓名笔画来算两个人关系的小测试,开发个这 ...

  6. vs2012 condition_variable notify_one 崩溃

    vs2012项目中用到 condition_variable系统方法,程序运行过程过程中偶尔出现notify_one崩溃, 程序运行的服务器系统版本是windows server 2008 R2 SP ...

  7. codeforces D. Queue 找规律+递推

    题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...

  8. LAMP环境的搭建

    [一些前言废话]一名web开发尤其是后端不懂LAMP环境的搭建,那就摊上事了,有些人说他一直用win下的wampServer这种傻瓜式环境搭建,用的挺好的,也有人说他用云服务器,搭配“一键搭建LAMP ...

  9. Matlab动态数组实现

    clear all; clc; a = []; %不是null,也不能什么都不是 for i=1:10 a = [a i]; end

  10. 博弈论入门小结 分类: ACM TYPE 2014-08-31 10:15 73人阅读 评论(0) 收藏

    文章原地址:http://blog.csdn.net/zhangxiang0125/article/details/6174639 博弈论:是二人或多人在平等的对局中各自利用对方的策略变换自己的对抗策 ...