MiaoheCMS v2.0 开发手册

本文档基于 MiaoheCMS v2.0 最新版本整理,包含所有可用模板标签、函数和实际使用示例。

本文档基于 MiaoheCMS v2.0 最新版本整理,包含所有可用模板标签、函数和实际使用示例。 最后更新:2026-08-03

一、模板文件结构

public/template/default/
├── index.htm          # 首页模板
├── list.htm           # 列表页模板
├── show.htm           # 内容详情页模板
├── page.htm           # 单页模板
├── search.htm         # 搜索结果页模板
├── header.htm         # 公共头部
├── footer.htm         # 公共底部
├── sidebar.htm        # 公共侧边栏
├── tag_list.htm       # 标签列表页模板
└── css/
    └── style.css      # 样式文件

二、变量输出

2.1 {$变量名} — 输出变量

{$title}              → 输出内容标题
{$head['title']}      → 输出 head 数组中的 title
{$MH['site_name']}    → 输出站点名称

自动包含 isset 检查,变量不存在时输出空字符串。

2.2 {SITE_URL} — 站点URL常量

<a href="{SITE_URL}">首页</a>

2.3 三元/空合并默认值

{$description?:'暂无描述'}
{$head['keywords']??''}

三、系统变量

模板中可以直接使用以下 PHP 变量:

变量 说明 可用页面
{$catid} 当前栏目ID(首页为0) 所有页面
{$id} 当前内容ID 内容页
{$page} 当前页码 列表页
{$title} 当前内容标题 内容页
{$content} 当前内容正文(HTML) 内容页
{$updatetime} 当前内容更新时间戳 内容页
{$keywords} 当前内容关键词 内容页
{$description} 当前内容描述 内容页
{$clicks} 当前内容点击数 内容页
{$comments} 当前内容评论数 内容页
{$MH} 站点配置数组 所有页面
{$head} 页面 head 信息 所有页面
{$keyword} 搜索关键词 搜索页
{$pagination} 分页HTML(控制器传入) 列表页

3.1 {$MH} 配置数组可用字段

字段 说明
{$MH['site_name']} 网站名称
{$MH['copyright']} 版权信息
{$MH['icpno']} 备案号
{$MH['tel']} 电话
{$MH['qq']} QQ
{$MH['address']} 地址
{$MH['company']} 公司名称
{$MH['email']} 邮箱
{$MH['zipcode']} 邮编
{$MH['contact']} 联系人
{$MH['mobile']} 手机

四、函数调用

4.1 {函数名(参数)} — 模板中调用 PHP 函数

函数 用途 示例
catname($catid) 获取栏目名称 {catname($catid)}
get_cat_type($catid) 获取栏目类型标识 {get_cat_type($catid)}
format_time($timestamp, $format) 格式化时间 {format_time($updatetime, 'Y-m-d H:i')}
friendly_time($timestamp) 友好时间(几秒前/几分钟前) {friendly_time($r['updatetime'])}
sub_string($str, $length, $suffix) UTF-8安全截取 {sub_string($r['title'], 30)}
strip_and_cut($str, $length) 去HTML标签后截取 {strip_and_cut($r['content'], 200)}
content_url($id, $catdir) 生成内容页URL {content_url($r['id'])}
thumb_url($src) 图片URL补全 {thumb_url($r['thumb'])}
h($str) HTML安全转义 {h($title)}
safe_text($str) 去除标签后转义 {safe_text($input)}
urlencode($str) URL编码 {urlencode($keyword)}
date($format) 当前日期 {date('Y')}
trim($str) 去除空白 {trim($tag)}
config($key, $default) 获取配置值 {config('site_url')}
csrf_field() CSRF令牌隐藏域 {csrf_field()}
nav_menu($parentid, $currentCatid) 生成导航菜单 {nav_menu(0, $catid)}
extract_first_image($html) 提取首张图片 {extract_first_image($content)}

4.2 使用示例

<!-- 格式化时间 -->
<span>{format_time($r['updatetime'], 'Y-m-d')}</span>

<!-- 友好时间 -->
<span>{friendly_time($r['updatetime'])}</span>

<!-- 标题截取20字 -->
<a href="{content_url($r['id'])}">{sub_string($r['title'], 20)}</a>

<!-- 内容摘要截取200字 -->
<p>{strip_and_cut($r['description']?:($r['content']?:''), 200)}</p>

<!-- 图片URL -->
<img src="{thumb_url($r['thumb'])}" alt="{$r['title']}">

五、控制流标签

5.1 {if}...{elseif}...{else}...{/if} — 条件判断

{if $catid==0}
    <!-- 首页专属内容 -->
{elseif $catid==1}
    <!-- 栏目1专属内容 -->
{else}
    <!-- 其他页面 -->
{/if}

<!-- 判断缩略图是否存在 -->
{if $r['thumb']}
    <img src="{thumb_url($r['thumb'])}" alt="{$r['title']}">
{/if}

<!-- 判断列表是否为空 -->
{if empty($list)}
    <div class="empty">暂无内容</div>
{/if}

支持运算符:== != > < >= <= && || !

5.2 {loop}...{/loop} — 循环遍历

二参数模式(只取value):

{loop $list $r}
    <h3>{$r['title']}</h3>
{/loop}

三参数模式(key => value):

{loop $list $key $r}
    <span>{$key}: {$r['title']}</span>
{/loop}

函数返回数组模式:

{loop explode(',', $keywords) $t}
    <a href="{SITE_URL}tags?tag={urlencode(trim($t))}">{trim($t)}</a>
{/loop}

循环内部可用 {$no} 输出从1开始的序号。

5.3 {for}...{/for} — for循环

{for $i=1; $i<=10; $i++}
    <span>{$i}</span>
{/for}

六、CMS内容标签

6.1 用途

调用指定条件的内容列表,不含分页。适合首页产品展示、侧边栏热门文章等场景。

6.2 参数说明

参数 说明 默认值 示例
catid 栏目ID,支持逗号分隔多个 0(全部) catid="9"catid="1,2,3"
row 返回条数 10 row="6"
limit 偏移量(跳过前N条) 0 limit="5"
orderby 排序字段 id id / updatetime / clicks / listorder / rand
orderbyway 排序方向 DESC DESC / ASC
withthumb 只取有缩略图的 0 withthumb="1"
subday 最近N天内 0 subday="7"
titlelen 标题截取长度(字符数) 0(不截取) titlelen="30"
infolen 描述截取长度(字符数) 0(不截取) infolen="100"
keyword 关键词筛选 keyword="PHP"
userid 用户ID筛选 all userid="1"
posid 推荐位ID 0 posid="1"
conditions 附加SQL条件 conditions="is_hot=1"

注意:当 catid 为单个栏目ID且该栏目有子栏目时,会自动包含子栏目的内容(v2.0+)。

6.3 可用变量

变量 说明
{$r['id']} 内容ID
{$r['catid']} 栏目ID
{$r['title']} 标题
{$r['thumb']} 缩略图路径
{$r['description']} 描述
{$r['content']} 正文(HTML)
{$r['keywords']} 关键词
{$r['clicks']} 点击数
{$r['comments']} 评论数
{$r['updatetime']} 更新时间戳
{$r['author']} 作者
{$r['username']} 发布者用户名
{$r['copyfrom']} 来源
{$r['is_hot']} 是否热门
{$r['is_recommend']} 是否推荐
{$r['is_top']} 是否头条
{$no} 循环序号(从1开始)

6.4 示例

<!-- 调用最新6篇文章 -->
{mh:content orderby="id" orderbyway="desc" row="6"}
<article>
    <h3><a href="{content_url($r['id'])}">{sub_string($r['title'], 30)}</a></h3>
    <p>{strip_and_cut($r['description']?:($r['content']?:''), 100)}</p>
    <span>{friendly_time($r['updatetime'])}</span>
</article>
{/mh:content}

<!-- 调用热门文章(按点击量排序,标题截取20字) -->
{mh:content orderby="clicks" row="10" titlelen="20"}
<li>
    <span class="rank">{$no}</span>
    <a href="{content_url($r['id'])}">{$r['title']}</a>
    <span>{$r['clicks']}阅读</span>
</li>
{/mh:content}

<!-- 调用指定栏目及其子栏目的最新内容 -->
{mh:content catid="9" orderby="id" row="6" titlelen="30" infolen="200"}
<div class="product-card">
    {if $r['thumb']}
    <img src="{thumb_url($r['thumb'])}" alt="{$r['title']}">
    {/if}
    <h3><a href="{content_url($r['id'])}">{$r['title']}</a></h3>
    <p>{$r['description']}</p>
</div>
{/mh:content}

<!-- 随机调用4篇 -->
{mh:content orderby="rand" row="4"}
...
{/mh:content}

<!-- 只要带缩略图的 -->
{mh:content withthumb="1" row="8" titlelen="30"}
...
{/mh:content}

<!-- 最近7天内的内容 -->
{mh:content subday="7" orderby="id" row="10"}
...
{/mh:content}

<!-- 按推荐位调用 -->
{mh:content posid="1" row="5" titlelen="30"}
...
{/mh:content}

七、列表标签

7.1 用途

用于栏目列表页,自动包含分页功能。通常配合 {$mh_page} 输出分页HTML。

7.2 参数说明

参数 说明 默认值 示例
catid 栏目ID $catid catid="$catid"
row 每页条数 10 row="15"
page 当前页码 $page page="$page"
orderby 排序字段 id id / updatetime / clicks
orderbyway 排序方向 DESC DESC / ASC
subday 最近N天内 0 subday="30"
titlelen 标题截取长度 0 titlelen="60"
infolen 描述截取长度 0 infolen="200"
keyword 关键词筛选 keyword="PHP"
conditions 附加SQL条件 conditions="is_hot=1"

注意{mh:list} 会自动包含子栏目内容,无需额外设置。

7.3 标签结束后可用变量

变量 说明
{$mh_page} 分页HTML字符串(含首页/上一页/页码/下一页/尾页)
{$mhcount} 总记录数
{$mhpagecount} 总页数

7.4 示例

<!-- 标准列表页 -->
<div class="breadcrumb">
    <a href="{SITE_URL}">首页</a> &gt;
    <span>{catname($catid)}</span>
</div>

<section class="list-section">
    <ul class="article-list">
        {mh:list catid="$catid" row="15" page="$page" titlelen="30" infolen="200"}
        <li class="article-item">
            {if $r['thumb']}
            <a href="{content_url($r['id'])}" class="thumb">
                <img src="{thumb_url($r['thumb'])}" alt="{sub_string($r['title'], 30)}" loading="lazy">
            </a>
            {/if}
            <div class="article-info">
                <h3><a href="{content_url($r['id'])}">{sub_string($r['title'], 30)}</a></h3>
                <p class="desc">{strip_and_cut($r['description']?:($r['content']?:''), 200)}</p>
                <div class="meta">
                    <span>{friendly_time($r['updatetime'])}</span>
                    <span>阅读({$r['clicks']})</span>
                    <span>评论({$r['comments']})</span>
                </div>
            </div>
        </li>
        {/mh:list}
    </ul>

    {if empty($list)}
    <div class="empty">暂无内容</div>
    {/if}
</section>

<!-- 分页 -->
<div class="pagination">
    {$mh_page}
</div>

八、栏目标签

8.1 用途

调用栏目数据,用于导航菜单、产品分类等。

8.2 参数说明

参数 说明 默认值 示例
catid / id 栏目ID 0 catid="$catid"
parentid 父栏目ID 0 parentid="0"
row 返回条数 100 row="10"
type 栏目类型筛选 all top(顶级) / son(子栏目) / self(同级) / all(所有)
mod 模型类型筛选 1,2,4 1,2,4
ismenu 只取菜单栏目 0 ismenu="1"
nav 导航类型(同ismenu) 0 nav="1"

8.3 可用变量

变量 说明
{$r['catid']} 栏目ID
{$r['catname']} 栏目名称
{$r['catdir']} 栏目目录名(英文别名)
{$r['url']} 栏目URL
{$r['image']} 栏目图片
{$r['description']} 栏目描述
{$r['parentid']} 父栏目ID
{$r['type']} 栏目类型(1=内部栏目, 2=单页, 4=外链)

8.4 示例

<!-- 顶部导航菜单 -->
<nav>
    {mh:category parentid="0" ismenu="1"}
    <a href="{SITE_URL}{$r['catdir']}/" {if $catid==$r['catid']}class="active"{/if}>
        {$r['catname']}
    </a>
    {/mh:category}
</nav>

<!-- 产品分类展示 -->
<div class="category-grid">
    {mh:category parentid="0" ismenu="1" row="8"}
    <a href="{SITE_URL}{$r['catdir']}/" class="category-card">
        <span class="cat-name">{$r['catname']}</span>
    </a>
    {/mh:category}
</div>

<!-- 获取当前栏目的子栏目 -->
{mh:category catid="$catid" type="son" row="10"}
<a href="{SITE_URL}{$r['catdir']}/">{$r['catname']}</a>
{/mh:category}

<!-- 底部产品分类 -->
{mh:category parentid="0" ismenu="1" row="6"}
<a href="{SITE_URL}{$r['catdir']}/">{$r['catname']}</a>
{/mh:category}

九、评论标签

9.1 用途

调用评论数据,用于侧边栏最新评论或内容页评论列表。

9.2 参数说明

参数 说明 默认值 示例
contentid 内容ID(筛选某篇文章的评论) 0 contentid="$id"
parentid 父评论ID 0 parentid="0"
row 每页条数 10 row="6"
page 页码 1 page="$page"

9.3 可用变量

变量 说明
{$r['id']} 评论ID
{$r['username']} 评论者昵称
{$r['content']} 评论内容
{$r['inputtime']} 评论时间戳
{$r['contentid']} 被评论的内容ID
{$r['support']} 点赞数
{$r['oppose']} 点踩数

9.4 示例

<!-- 侧边栏最新评论 -->
<div class="widget">
    <h3>最新评论</h3>
    <ul>
        {mh:comment row="6"}
        <li>
            <span class="comment-user">{$r['username']}:</span>
            <a href="{content_url($r['contentid'])}#comment">
                {strip_and_cut($r['content'], 40)}
            </a>
        </li>
        {/mh:comment}
    </ul>
</div>

十、通用表查询

10.1 用途

直接查询数据库中的任意表,可用于友情链接、自定义数据等。

10.2 参数说明

参数 说明 默认值 示例
row 返回条数 10 row="20"
orderby 排序字段 id orderby="listorder"
orderbyway 排序方向 DESC orderbyway="ASC"
where WHERE条件 1=1 where="isindex=1"
page 分页页码 0(不分页) page="1"
fields 查询字段 * fields="name,url,logo"

10.3 示例

<!-- 友情链接 -->
<div class="friend-links">
    {table:link where="isindex=1" orderby="listorder" row="20"}
    <a href="{$r['url']}" target="_blank" rel="nofollow">{$r['name']}</a>
    {/table:link}
</div>

<!-- 带Logo的友链 -->
{table:link where="logo!=''" orderby="listorder" row="10"}
<a href="{$r['url']}" target="_blank">
    <img src="{$r['logo']}" alt="{$r['name']}">
</a>
{/table:link}

<!-- 自定义查询 -->
{table:guestbook where="status=1" orderby="id" row="10"}
<div>
    <strong>{$r['username']}</strong>
    <p>{$r['content']}</p>
</div>
{/table:guestbook}

十一、SQL查询

11.1 用途

执行自定义SQL查询(仅允许SELECT,安全限制)。

注意: 从 v2.0 起,外部数据库连接功能已被禁用,仅支持查询当前站点数据库。

11.2 示例

<!-- 标签云 -->
{mh:sql sql="SELECT tag, COUNT(*) as cnt FROM {prefix}tag GROUP BY tag ORDER BY cnt DESC LIMIT 20"}
<a href="{SITE_URL}tags?tag={urlencode($r['tag'])}">{$r['tag']}({$r['cnt']})</a>
{/mh:sql}

<!-- 统计查询 -->
{mh:sql sql="SELECT COUNT(*) AS cnt FROM {prefix}content WHERE status=1"}
<span>共有 {$r['cnt']} 篇文章</span>
{/mh:sql}

{prefix} 会自动替换为实际的表前缀。


十二、友情链接

12.1 用途

调用友情链接数据(也可用 {table:link} 替代)。

12.2 参数说明

参数 说明 默认值 示例
row 返回条数 20 row="10"
withlogo 只要带Logo的 0 withlogo="1"
isindex 是否首页显示 0 isindex="1"
typeid 分类ID all typeid="1"

十三、分页标签

13.1 用途

获取分页数据(页码、总数等),用于自定义分页样式。

13.2 参数

13.3 可用变量

变量 说明
{$totalcount} 总记录数
{$pageno} 总页数
{$page} 当前页码
{$index} 第一页页码
{$pre} 上一页页码
{$next} 下一页页码
{$end} 最后一页页码

十四、上一篇/下一篇

14.1 {getpre($id, $catid, $len)} — 上一篇

{getpre($id, $catid, 40)}

输出格式:<a href="URL">标题(截取40字)</a>

注意: 默认输出不含箭头和"上一篇"标签,如需箭头可通过 CSS ::before 伪元素添加。

14.2 {getnext($id, $catid, $len)} — 下一篇

{getnext($id, $catid, 40)}

输出格式:<a href="URL">标题(截取40字)</a>

注意: 默认输出不含箭头和"下一篇"标签,如需箭头可通过 CSS ::before 伪元素添加。

14.3 {content_pre} — 上一篇(模板变量)

依赖: 控制器必须传入 $prev 变量。仅在控制器已实现传值时有效。

{content_pre}

输出格式:<a href="URL">← 标题</a>(内置 箭头)

14.4 {content_next} — 下一篇(模板变量)

依赖: 控制器必须传入 $next 变量。仅在控制器已实现传值时有效。

{content_next}

输出格式:<a href="URL">标题 →</a>(内置 箭头)

14.5 使用示例

<div class="article-nav">
    {getpre($id, $catid, 40)}
    {getnext($id, $catid, 40)}
</div>

十五、广告标签

15.1 基本用法

ad 表中查询广告数据,常用于首页横幅、侧边栏广告等。

{mh:ad row="5" orderby="listorder" orderbyway="ASC"}
<div class="ad-item">
    <a href="{$r['url']}" target="_blank">
        <img src="{$r['image']}" alt="{$r['name']}">
    </a>
</div>
{/mh:ad}

15.2 参数说明

参数 说明 默认值 示例
row 返回条数 10 row="5"
orderby 排序字段 id orderby="listorder"
orderbyway 排序方向 DESC ASC
where 附加WHERE条件 where="typeid=1"

15.3 可用字段

字段 说明
{$r['id']} 广告ID
{$r['name']} 广告名称
{$r['url']} 广告链接
{$r['image']} 广告图片
{$r['description']} 广告描述
{$r['listorder']} 排序值

十六、模板自定义标签

16.1 基本用法

tag_library 表中读取预先定义好的 HTML/文本片段。

前提: 需先在后台管理 → 标签管理中定义标签名称及其内容。

{label:copyright}      → 输出版权信息
{label:notice}         → 输出公告
{label:contact_info}   → 输出联系方式
<footer>
    {label:copyright}
    {label:icp}
</footer>

十七、JS输出标签

17.1 基本用法

{$变量名} 类似,但会在输出时对特殊字符做 JavaScript 转义处理,适合在 <script> 标签中嵌入 PHP 变量。

<script>
    var title = '{js:title}';         → 对标题中的引号做转义
    var catid = {js:catid};           → 数字直接输出
    var siteUrl = '{js:SITE_URL}';    → 站点URL
</script>

注意: {js:变量名}{$变量名} 的区别在于自动添加转义处理,避免 JS 语法错误。


十八、模板包含

18.1 {include 模板路径} — 包含子模板

{include template/default/header.htm}
{include template/default/footer.htm}
{include template/default/sidebar.htm}

十九、插件钩子

19.1 {hook:插件名} — 调用插件

{hook:plugin_name}
{hook:plugin_name args:$param1,$param2}

二十、PHP执行

20.1 {mhcms PHP代码} — 执行PHP

{mhcms $var = config('site.site_name');}

安全限制:只允许白名单内的函数调用。


二十一、字段输出

21.1 {field:字段名} — 在CMS标签内输出字段

{mh:content row="5"}
    <h3>{field:title}</h3>       <!-- 等同于 {$r['title']} -->
    <p>{field:description}</p>   <!-- 等同于 {$r['description']} -->
{/mh:content}

二十二、标签速查表

标签语法 功能 分页 子栏目自动包含
{$var} 输出变量 - -
{SITE_URL} 站点URL - -
{函数名(参数)} 函数调用 - -
{if}...{/if} 条件判断 - -
{loop}...{/loop} 循环遍历 - -
{for}...{/for} for循环 - -
{mh:content}...{/mh:content} 内容调用 ✓(单个catid时)
{mh:list}...{/mh:list} 列表调用
{mh:category}...{/mh:category} 栏目调用 -
{table:xxx}...{/table:xxx} 通用表查询 -
{mh:sql}...{/mh:sql} SQL查询 -
{mh:comment}...{/mh:comment} 评论调用 -
{mh:flink}...{/mh:flink} 友情链接 -
{mh:ad}...{/mh:ad} 广告调用 -
{label:标签名} 自定义标签 - -
{js:变量名} JS安全输出 - -
{mh:pagelist}...{/mh:pagelist} 分页数据 - -
{getpre(...)} 上一篇(直接输出链接) - -
{getnext(...)} 下一篇(直接输出链接) - -
{content_pre} 上一篇(控制器变量) - -
{content_next} 下一篇(控制器变量) - -
{include ...} 包含模板 - -
{hook:xxx} 插件钩子 - -
{mhcms ...} 执行PHP - -
{csrf_field()} CSRF令牌 - -
{field:xxx} 字段输出 - -

二十三、完整页面示例

23.1 首页示例

{include template/default/header.htm}

<!-- Banner / 轮播 -->
<section class="banner">
    <div class="swiper swiper-banner">
        <div class="swiper-wrapper">
            <div class="swiper-slide">
                <div class="slide-content">
                    <h1>{$MH['site_name']}</h1>
                    <p>{$MH['meta_description']}</p>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- 产品分类导航 -->
<section class="category-section">
    <div class="category-grid">
        {mh:category parentid="0" ismenu="1" row="8"}
        <a href="{SITE_URL}{$r['catdir']}/" class="category-card">
            <span class="cat-name">{$r['catname']}</span>
        </a>
        {/mh:category}
    </div>
</section>

<!-- 热门产品 -->
<section class="products-section">
    <div class="section-header">
        <h2>热门<span class="accent-text">产品</span></h2>
    </div>
    <div class="products-grid">
        {mh:content orderby="clicks" orderbyway="desc" row="6" titlelen="30"}
        <article class="product-card">
            {if $r['thumb']}
            <div class="card-img">
                <img src="{thumb_url($r['thumb'])}" alt="{$r['title']}" loading="lazy">
            </div>
            {/if}
            <h3><a href="{content_url($r['id'])}">{sub_string($r['title'], 30)}</a></h3>
            <p>{strip_and_cut($r['description']?:($r['content']?:''), 80)}</p>
        </article>
        {/mh:content}
    </div>
</section>

<!-- 新闻资讯 -->
<section class="news-section">
    <div class="section-header">
        <h2>行业<span class="accent-text">动态</span></h2>
    </div>
    <div class="news-grid">
        {mh:content orderby="id" orderbyway="desc" row="6" titlelen="30"}
        <article class="news-card">
            {if $r['thumb']}
            <div class="news-img">
                <img src="{thumb_url($r['thumb'])}" alt="{$r['title']}" loading="lazy">
            </div>
            {/if}
            <div class="news-info">
                <h3><a href="{content_url($r['id'])}">{$r['title']}</a></h3>
                <p>{strip_and_cut($r['description']?:($r['content']?:''), 80)}</p>
                <span>{friendly_time($r['updatetime'])}</span>
            </div>
        </article>
        {/mh:content}
    </div>
</section>

{include template/default/footer.htm}

23.2 列表页示例

{include template/default/header.htm}

<div class="breadcrumb">
    <a href="{SITE_URL}">首页</a> &gt;
    <span>{catname($catid)}</span>
</div>

<main class="main">
    <div class="content-wrap">
        <section class="list-section">
            <ul class="article-list">
                {mh:list catid="$catid" row="15" page="$page" titlelen="30" infolen="200"}
                <li class="article-item">
                    {if $r['thumb']}
                    <a href="{content_url($r['id'])}" class="thumb">
                        <img src="{thumb_url($r['thumb'])}" alt="{sub_string($r['title'], 30)}" loading="lazy">
                    </a>
                    {/if}
                    <div class="article-info">
                        <h3><a href="{content_url($r['id'])}">{sub_string($r['title'], 30)}</a></h3>
                        <p class="desc">{strip_and_cut($r['description']?:($r['content']?:''), 200)}</p>
                        <div class="meta">
                            <span>{friendly_time($r['updatetime'])}</span>
                            <span>阅读({$r['clicks']})</span>
                        </div>
                    </div>
                </li>
                {/mh:list}
            </ul>

            {if empty($list)}
            <div class="empty">暂无内容</div>
            {/if}
        </section>

        <div class="pagination">{$mh_page}</div>
    </div>

    {include template/default/sidebar.htm}
</main>

{include template/default/footer.htm}

23.3 内容详情页示例

{include template/default/header.htm}

<div class="breadcrumb">
    <a href="{SITE_URL}">首页</a> &gt;
    {mh:category catid="$catid"}
    <a href="{SITE_URL}{$r['catdir']}/">{$r['catname']}</a>
    {/mh:category}
    <span>正文</span>
</div>

<main class="main">
    <div class="content-wrap">
        <article class="article-detail">
            <h1>{$title}</h1>
            <div class="meta">
                <span>发布时间:{format_time($updatetime, 'Y-m-d H:i')}</span>
                <span>阅读:{$clicks}</span>
                <span>评论:{$comments}</span>
            </div>

            <div class="content">
                {$content}
            </div>

            {if $keywords}
            <div class="tags">
                {loop explode(',', $keywords) $t}
                {if trim($t)}
                <a href="{SITE_URL}tags?tag={urlencode(trim($t))}">{trim($t)}</a>
                {/if}
                {/loop}
            </div>
            {/if}

            <div class="article-nav">
                {getpre($id, $catid, 40)}
                {getnext($id, $catid, 40)}
            </div>
        </article>
    </div>

    {include template/default/sidebar.htm}
</main>

{include template/default/footer.htm}

23.4 侧边栏示例

<aside class="sidebar">
    <!-- 搜索 -->
    <div class="widget widget-search">
        <form action="{SITE_URL}search" method="get">
            <input type="text" name="q" placeholder="搜索内容..." value="{$keyword??''}">
            <button type="submit">搜索</button>
        </form>
    </div>

    <!-- 热门文章 -->
    <div class="widget widget-hot">
        <h3>热门文章</h3>
        <ul>
            {mh:content orderby="clicks" row="10" titlelen="20"}
            <li>
                <span class="rank-num">{$no}</span>
                <a href="{content_url($r['id'])}">{sub_string($r['title'], 20)}</a>
                <span class="clicks">{$r['clicks']}阅读</span>
            </li>
            {/mh:content}
        </ul>
    </div>

    <!-- 最新评论 -->
    <div class="widget widget-comments">
        <h3>最新评论</h3>
        <ul>
            {mh:comment row="6"}
            <li>
                <span class="comment-user">{$r['username']}:</span>
                <a href="{content_url($r['contentid'])}#comment">
                    {strip_and_cut($r['content'], 40)}
                </a>
            </li>
            {/mh:comment}
        </ul>
    </div>

    <!-- 热门标签 -->
    <div class="widget widget-tags">
        <h3>热门标签</h3>
        <div class="tag-cloud">
            {mh:sql sql="SELECT tag, COUNT(*) as cnt FROM {prefix}tag GROUP BY tag ORDER BY cnt DESC LIMIT 20"}
            <a href="{SITE_URL}tags?tag={urlencode($r['tag'])}">{$r['tag']}</a>
            {/mh:sql}
        </div>
    </div>

    <!-- 友情链接 -->
    <div class="widget widget-links">
        <h3>友情链接</h3>
        <ul>
            {table:link where="isindex=1" orderby="listorder" row="20"}
            <li><a href="{$r['url']}" target="_blank" rel="nofollow">{$r['name']}</a></li>
            {/table:link}
        </ul>
    </div>
</aside>

文档版本:v2.0
适用系统:MiaoheCMS v2.0
模板目录:public/template/default/
模板缓存:storage/tplcache/

文档版本:v2.0 · 适用系统:MiaoheCMS v2.0 · 模板目录:public/template/default/ · 缓存目录:storage/tplcache/