停更了一个月后,咱们再次开始更新。具体缘由只能说是过年事情太多,幼时不知努力,长大了却又事事缠身。java
这一期主要是根据WordPress执行的效果来观察数据库,从而分析WordPress的程序设计。mysql
项目github地址:github.com/pc859107393…android
个人简书首页是:www.jianshu.com/users/86b79…git
上一期是:[手把手教程][第二季]java 后端博客系统文章系统——No4github
根据WordPress文章保存和草稿保存分析程序设计web
首先咱们打开WordPress登陆到控制台后随便保存草稿和文章,而后导出数据库中posts表增长内容以下:spring
{
"RECORDS":[
{
"ID":"329",
"post_author":"1",
"post_date":"02-16-2017 09:57:29",
"post_date_gmt":"02-16-2017 01:57:29",
"post_title":"[java 手把手教程][第二季]java 后端博客系统文章系统——No4",
"post_excerpt":"",
"post_status":"inherit",
"comment_status":"closed",
"comment_count":"0",
"ping_status":"closed",
"post_password":"",
"post_name":"328-revision-v1",
"to_ping":"",
"pinged":"",
"post_modified":"02-16-2017 09:57:29",
"post_modified_gmt":"02-16-2017 01:57:29",
"post_content_filtered":"",
"post_parent":"328",
"guid":"http://acheng1314.cn/?p=329",
"menu_order":"0",
"post_type":"revision",
"post_mime_type":"",
"comment_count(2)":"0"
},
{
"ID":"328",
"post_author":"1",
"post_date":"02-16-2017 09:58:19",
"post_date_gmt":"02-16-2017 01:58:19",
"post_title":"[java 手把手教程][第二季]java 后端博客系统文章系统——No4",
"post_excerpt":"",
"post_status":"publish",
"comment_status":"open",
"comment_count":"0",
"ping_status":"open",
"post_password":"",
"post_name":"java-%e6%89%8b%e6%8a%8a%e6%89%8b%e6%95%99%e7%a8%8b%e7%ac%ac%e4%ba%8c%e5%ad%a3java-%e5%90%8e%e7%ab%af%e5%8d%9a%e5%ae%a2%e7%b3%bb%e7%bb%9f%e6%96%87%e7%ab%a0%e7%b3%bb%e7%bb%9f-no4",
"to_ping":"",
"pinged":"",
"post_modified":"02-16-2017 09:58:19",
"post_modified_gmt":"02-16-2017 01:58:19",
"post_content_filtered":"",
"post_parent":"0",
"guid":"http://acheng1314.cn/?p=328",
"menu_order":"0",
"post_type":"post",
"post_mime_type":"",
"comment_count(2)":"0"
},
{
"ID":"327",
"post_author":"1",
"post_date":"02-14-2017 23:20:15",
"post_date_gmt":"02-14-2017 15:20:15",
"post_title":"个人草稿",
"post_excerpt":"",
"post_status":"inherit",
"comment_status":"closed",
"comment_count":"0",
"ping_status":"closed",
"post_password":"",
"post_name":"323-revision-v1",
"to_ping":"",
"pinged":"",
"post_modified":"02-14-2017 23:20:15",
"post_modified_gmt":"02-14-2017 15:20:15",
"post_content_filtered":"",
"post_parent":"323",
"guid":"http://acheng1314.cn/?p=327",
"menu_order":"0",
"post_type":"revision",
"post_mime_type":"",
"comment_count(2)":"0"
},
{
"ID":"326",
"post_author":"1",
"post_date":"02-14-2017 23:20:01",
"post_date_gmt":"02-14-2017 15:20:01",
"post_title":"",
"post_excerpt":"",
"post_status":"inherit",
"comment_status":"closed",
"comment_count":"0",
"ping_status":"closed",
"post_password":"",
"post_name":"323-revision-v1",
"to_ping":"",
"pinged":"",
"post_modified":"02-14-2017 23:20:01",
"post_modified_gmt":"02-14-2017 15:20:01",
"post_content_filtered":"",
"post_parent":"323",
"guid":"http://acheng1314.cn/?p=326",
"menu_order":"0",
"post_type":"revision",
"post_mime_type":"",
"comment_count(2)":"0"
},
{
"ID":"325",
"post_author":"1",
"post_date":"02-10-2017 22:34:41",
"post_date_gmt":"00-00-00 00:00:00",
"post_title":"自动草稿",
"post_excerpt":"",
"post_status":"auto-draft",
"comment_status":"open",
"comment_count":"0",
"ping_status":"open",
"post_password":"",
"post_name":"",
"to_ping":"",
"pinged":"",
"post_modified":"02-10-2017 22:34:41",
"post_modified_gmt":"00-00-00 00:00:00",
"post_content_filtered":"",
"post_parent":"0",
"guid":"http://acheng1314.cn/?p=325",
"menu_order":"0",
"post_type":"post",
"post_mime_type":"",
"comment_count(2)":"0"
},
{
"ID":"323",
"post_author":"1",
"post_date":"02-14-2017 23:20:15",
"post_date_gmt":"00-00-00 00:00:00",
"post_title":"个人草稿",
"post_excerpt":"",
"post_status":"draft",
"comment_status":"open",
"comment_count":"0",
"ping_status":"open",
"post_password":"",
"post_name":"",
"to_ping":"",
"pinged":"",
"post_modified":"02-14-2017 23:20:15",
"post_modified_gmt":"02-14-2017 15:20:15",
"post_content_filtered":"",
"post_parent":"0",
"guid":"http://acheng1314.cn/?p=323",
"menu_order":"0",
"post_type":"post",
"post_mime_type":"",
"comment_count(2)":"0"
}
]
}复制代码
在上面的数据中咱们已经删除了文章内容的数据(数据量太大,不方便查阅)。而后咱们仔细分析上面的json数据,咱们能够得出结论以下:sql
经过上面的对比咱们大体能够得出这样一个结论:数据库
---->正式发布
"post_status":"publish",
"comment_status":"open",
"ping_status":"open",
"post_name":"java-%e6%89%8b%e6%8a%8a%e6%89%8b%e6%95%99%e7%a8%8b%e7%ac%ac%e4%ba%8c%e5%ad%a3java-%e5%90%8e%e7%ab%af%e5%8d%9a%e5%ae%a2%e7%b3%bb%e7%bb%9f%e6%96%87%e7%ab%a0%e7%b3%bb%e7%bb%9f-no4",
"post_type":"post",
"post_parent":"0",
---->历史记录
"post_status":"inherit",
"comment_status":"closed",
"ping_status":"closed",
"post_name":"328-revision-v1",
"post_type":"revision",
"post_parent":"328",复制代码
草稿:json
小结:
文章分组相关分析
SELECT
`ID`,
`post_title`,
`post_date`,
`post_content`
FROM
`wp_posts`
WHERE
`post_type` = 'post'
AND
`post_status` = 'publish'
ORDER BY
`ID`复制代码
上面的语句可以查找出来公开的文章,文章ID一目了然。
同时咱们观察数据库能够得出跟文章的归类相关的数据库有:
可是这么多表都是文章分类相关的东西,那么文章分类又分为何些呢?按照WordPress的简单构架支撑大量的数据来看,那么咱们能够确定文章标签和目录分类确定是在一块儿的。因此咱们先看最根本的wp_terms。
term_id | name | slug | term_group |
---|---|---|---|
1 | java web | java-web | 0 |
2 | C语言学习 | how2use_c | 0 |
3 | Android开发 | makeandroid | 0 |
4 | 综合总结 | all_log | 0 |
5 | 我的生活 | myself_life | 0 |
6 | post-format-aside | post-format-aside | 0 |
7 | 转载 | from_others | 0 |
8 | Android Coder | android-coder | 0 |
9 | 友情连接 | %e5%8f%8b%e6%83%85%e9%93%be%e6%8e%a5 | 0 |
10 | JavaWeb | javaweb | 0 |
11 | java web | java-web | 0 |
12 | Spring | spring | 0 |
13 | Mybatis | mybatis | 0 |
14 | java后端 | java%e5%90%8e%e7%ab%af | 0 |
15 | JavaWeb | javaweb | 0 |
16 | MySQL数据库 | mysql%e6%95%b0%e6%8d%ae%e5%ba%93 | 0 |
17 | 全栈教程 | %e5%85%a8%e6%a0%88%e6%95%99%e7%a8%8b | 0 |
18 | java | java | 0 |
上面这张表是我线上服务器上面的wp_term表,可能咱们暂时不明白什么意思,不过问题不大。咱们接着看wp_term_taxonomy。
term_taxonomy_id | term_id | taxonomy | description | parent | count |
---|---|---|---|---|---|
1 | 1 | category | 0 | 17 | |
2 | 2 | category | 0 | 0 | |
3 | 3 | category | 0 | 20 | |
4 | 4 | category | 0 | 6 | |
5 | 5 | category | 0 | 1 | |
6 | 6 | post_format | 0 | 44 | |
7 | 7 | category | 0 | 8 | |
8 | 8 | link_category | 0 | 2 | |
9 | 9 | nav_menu | 0 | 0 | |
10 | 10 | link_category | 0 | 0 | |
11 | 11 | post_tag | 0 | 2 | |
12 | 12 | post_tag | 0 | 4 | |
13 | 13 | post_tag | 0 | 4 | |
14 | 14 | post_tag | 0 | 3 | |
15 | 15 | post_tag | 0 | 2 | |
16 | 16 | post_tag | 0 | 3 | |
17 | 17 | post_tag | 0 | 3 | |
18 | 18 | post_tag | 0 | 1 |
经过上面这种表咱们就能够明白了term_id所对应的name分别是什么用的,他们分别有文章分组、文章标签、连接标记等。
可是说这么多都没把上面文章的文章分类在哪找到,因此咱们接着看wp_term_relationships表里面的东西。
object_id | term_taxonomy_id | term_order |
---|---|---|
1 | 8 | 0 |
2 | 8 | 0 |
9 | 4 | 0 |
9 | 6 | 0 |
11 | 4 | 0 |
11 | 6 | 0 |
16 | 3 | 0 |
16 | 6 | 0 |
··· | ··· | ··· |
表里面数据还有不少此处暂时省略。
上面表中的object_id顾名思义就是说对象的ID,说明它不单是文章也还有其余分类的信息。
咱们再看看咱们线上的wp_posts(文章)表,里面的简略内容以下:
ID | post_title | post_date | post_content |
---|---|---|---|
9 | IT产品文档列表 | 2015-09-22 16:44:48 | 内容省略··· |
11 | 建站伊始,一切从头再来,本站用wordpress搭建,基于PHP。 | 2015-09-22 16:45:32 | ··· |
其实数据不须要那么多,咱们只须要一丢丢数据简单对比就能知道结果了。
term_id | taxonomy |
---|---|
category | post_format |
term_id | name | slug | term_group |
---|---|---|---|
4 | 综合总结 | all_log | 0 |
6 | post-format-aside | post-format-aside | 0 |
因此最后咱们经过这样就能够明白分类信息的大概查找结构,文章分类的大概查找以下:
文章id ➡ wp_term_relationships中的object_id对应的term_taxonomy_id ➡ wp_term_taxonomy的ID能够看到分别是什么分类同时能够查找到term_id ➡ 最后在wp_term表中根据term_id能够查找到具体的名称。
至此分类信息基本查找完成。
总结