主题目录
usr/theme/my-theme/
├── home.php # 首页模板(存在即接管首页渲染)
├── post.php # 文章页模板(文档式阅读/产品页用)
├── list_common.php # 列表模板(分类/标签/搜索/归档通用)
├── page.php # 独立页面模板
├── theme.css # 主题样式(含 @Version 注释用于云端版本)
├── functions.php # 主题函数(可选)
└── screenshot.png # 云端市场截图
模板加载顺序
- 核心渲染流程:index.php →
themeTemplate('home') 存在则 require 并 exit,否则走默认列表渲染;
- post.php 同理:主题带 post.php 时文章页完全由主题模板渲染(可用 $post/$tags/$comments/$rendered/$tocList 等变量);
- list_common.php 供分类/标签/搜索/归档页复用列表布局。
模板内可用函数
publicHeader()/publicFooter():公共页头页脚(含统计代码钩子);
renderPostCard($post):列表卡片;renderPager($cur,$total,$urlFn):窗口分页;
postUrl()/categoryUrl()/tagUrl()/archiveUrl():URL 生成(语言感知);
getOption()/L()/esc():选项/双语/转义;doHook():主题内可触发钩子。
主题与站点设置对接
- 主题通过
getOption('xxx') 读取站点设置(如 Hero 标题/按钮、页脚文案),后台无需改代码即可换文案;
- 自建 <html> 模板的主题必须自行输出
footerStats()(统计代码)与 doHook('footer'),否则统计/钩子不生效。
发布打包
php tools/cli_pack.php usr/theme/my-theme # 云端包(theme.css 需含 @Version)
# 上传 cloud/themes/ 目录