前言:wordpress数据库,编码使用utf8_general_ci
https://wphierarchy.com/

程序文件结构

文件夹

wp-admin 后台管理
wp-content 插件/主题/语言包/媒体库
wp-includes 核心文件库
images 图片文件

模板层级

WordPress-Template-Hierarchy.png
WordPress模板层级 - 图2

归档页

作者归档页
author-$nicename.php($nicename 代表作者用户名)
当寻找作者归档页,WordPress首先寻找 author-admin.php 或 author-rand.php 文件 ,假如没有这两个文件则跳到author-$id.php。
author-$id.php($id 代表作者编号)
author.php (作者归档页文件)
如果没有主题内没有 以上3个文件,侧直接引用 author.php
优先级: author-$nicename.php > author-$id.php > author.php > archive.php > paged.php(分页) > index.php

分类归档页/标签归档页(以分类为例)
category-$slug.php ($slug 代表分类目录的别名)
category-$id.php ($id 代表分类目录的编号)
category.php (分类归档页文件)
优先级:category-$slug.php > category-$id.php > category.php > archive.php > paged.php(分页) > index.php


内容页

附件详情页
$mimetype.php (mime type 表示图像的大类型 如:image)
当访问图片对应附件详情页的时候,WordPress 首先在主题内寻找 image.php 这个文件。
$subtype.php (sub type 表示图像的子类型 如:jpeg)
如果找不到 image.php 这个文件,则寻找 jpeg.php
如果找不到 jpeg.php 这个文件,则寻找 image_jpeg.php
优先级:$mimetype.php > $subtype.php > $mimetype_$subtype.php > attachment.php > single.php > singular.php > index.php

文章详细页
优先级:single-post.php > single.php > singular.php > index.php

页面详情页
如何创建自定义模板
在主题文件夹中随意创建一个php文件,头部需要添加 / Template Name: xxx.php /

  1. 如:
  2. <?php
  3. /* Template Name:xxx.php */
  4. ?>

使用默认模板
page-$slug.php ($slug 代表作者名)
优先级:page-$slug.php > page-$id.php > page.php > index.php

使用自定义模板
优先级:$custom.php > page-$slug.php > page-$id.php > page.php > index.php

主题构成

  1. 模板文件(模板层级的那些文件,index.php / single.php / page.php 等 )
  2. 样式文件(style.css 文件,而且要符合WordPress规则的头部说明信息)
  3. 预览图片(screenshot.png ,主题图片显示)
  4. 功能文件(functions.php,用于WordPress添加功能、减少功能或修改现有的功能)
  5. 网页文件(图片文件、js文件、css文件)