MiaoheCMS v2.0 开发手册 v2.0
本文档基于 MiaoheCMS v2.0 最新版本整理,包含所有可用模板标签、函数和实际使用示例。
最后更新:2026-07-09
一、模板文件结构
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']} | |
{$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内容标签 {mh:content}
6.1 用途
调用指定条件的内容列表,不含分页。适合首页产品展示、侧边栏热门文章等场景。
6.2 参数说明
| 参数 | 说明 | 默认值 | 示例 |
|---|---|---|---|
catid | 栏目ID,支持逗号分隔多个 | 0(全部) | catid="9" 或 catid="1,2,3" |
status | 内容状态 | 1 | status="1" |
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 status="1" 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 status="1" 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" status="1" 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 status="1" orderby="rand" row="4"}
...
{/mh:content}
<!-- 只要带缩略图的 -->
{mh:content status="1" withthumb="1" row="8" titlelen="30"}
...
{/mh:content}
<!-- 最近7天内的内容 -->
{mh:content status="1" subday="7" orderby="id" row="10"}
...
{/mh:content}
<!-- 按推荐位调用 -->
{mh:content status="1" posid="1" row="5" titlelen="30"}
...
{/mh:content}
七、列表标签 {mh:list}
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> >
<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>
八、栏目标签 {mh:category}
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:comment}
9.1 用途
调用评论数据,用于侧边栏最新评论或内容页评论列表。
9.2 参数说明
| 参数 | 说明 | 默认值 | 示例 |
|---|---|---|---|
contentid | 内容ID(筛选某篇文章的评论) | 0 | contentid="$id" |
parentid | 父评论ID | 0 | parentid="0" |
row | 每页条数 | 10 | row="6" |
page | 页码 | 1 | page="$page" |
orderby | 排序字段 | id | inputtime |
status | 审核状态 | 1 | status="1" |
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 status="1" orderby="inputtime" 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>
十、通用表查询 {table:表名}
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" |
isindex | 快捷条件:是否首页显示 | - | isindex="1" |
10.3 示例
<!-- 友情链接 -->
<div class="friend-links">
{table:link 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查询 {mh:sql}
11.1 用途
执行自定义SQL查询(仅允许SELECT,安全限制)。
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} 会自动替换为实际的表前缀。
十二、友情链接 {mh:flink}
12.1 用途
调用友情链接数据(也可用 {table:link} 替代)。
12.2 参数说明
| 参数 | 说明 | 默认值 | 示例 |
|---|---|---|---|
row | 返回条数 | 20 | row="10" |
withlogo | 只要带Logo的 | 0 | withlogo="1" |
isindex | 是否首页显示 | 0 | isindex="1" |
typeid | 分类ID | all | typeid="1" |
十三、分页标签 {mh:pagelist}
13.1 用途
获取分页数据(页码、总数等),用于自定义分页样式。
13.2 参数
listsize— 列表每页数量
13.3 可用变量
| 变量 | 说明 |
|---|---|
{$totalcount} | 总记录数 |
{$pageno} | 总页数 |
{$page} | 当前页码 |
{$index} | 第一页页码 |
{$pre} | 上一页页码 |
{$next} | 下一页页码 |
{$end} | 最后一页页码 |
十四、上一篇/下一篇
14.1 {getpre($id, $catid, $len)} — 上一篇
{getpre($id, $catid, 40)}
输出格式:<a href="URL">← 标题(截取40字)</a>
14.2 {getnext($id, $catid, $len)} — 下一篇
{getnext($id, $catid, 40)}
输出格式:<a href="URL">标题(截取40字) →</a>
14.3 使用示例
<div class="article-nav">
{getpre($id, $catid, 40)}
{getnext($id, $catid, 40)}
</div>
十五、模板包含
15.1 {include 模板路径} — 包含子模板
{include template/default/header.htm}
{include template/default/footer.htm}
{include template/default/sidebar.htm}
十六、插件钩子
16.1 {hook:插件名} — 调用插件
{hook:plugin_name}
{hook:plugin_name args:$param1,$param2}
十七、PHP执行 {mhcms}
17.1 {mhcms PHP代码} — 执行PHP
{mhcms $var = config('site.site_name');}
安全限制:只允许白名单内的函数调用。
十八、字段输出 {field:}
18.1 {field:字段名} — 在CMS标签内输出字段
{mh:content status="1" 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:pagelist}...{/mh:pagelist} | 分页数据 | - | - |
{getpre(...)} | 上一篇 | - | - |
{getnext(...)} | 下一篇 | - | - |
{include ...} | 包含模板 | - | - |
{hook:xxx} | 插件钩子 | - | - |
{mhcms ...} | 执行PHP | - | - |
{csrf_field()} | CSRF令牌 | - | - |
{field:xxx} | 字段输出 | - | - |
二十、完整页面示例
20.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 status="1" 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 status="1" 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}
20.2 列表页示例
{include template/default/header.htm}
<div class="breadcrumb">
<a href="{SITE_URL}">首页</a> >
<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}
20.3 内容详情页示例
{include template/default/header.htm}
<div class="breadcrumb">
<a href="{SITE_URL}">首页</a> >
{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}
20.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 status="1" 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 status="1" orderby="inputtime" 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 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/