在学习Z-Blog模板标签之家大家应注意下面3点:
1. Z-BlogPHP 1.5之前的版本,在主题目录下会有一个compile文件夹,这里存放经过程序编译后的模板文件,请不要去修改。
2. 如果改动了模板文件,则需要重新编译模板才能看到改动效果。你可以在后台首页找到[清空缓存并重新编译模板]或重新激活主题刷新编译模板文件。
3. Z-BlogPHP模版标签调用方式为{$类名.(二级类名.)类属性},如
[b]{$article.Title}:[/b]
显示文章标题的标签。这里article为文章类,Title为文章类属性。
[b]{$article.Category.Name}:[/b]
显示文章的分类名称。这里article为文章类名,而Category则为二级类,Name为类属性
了解上面3点后大家可以看一下Z-Blog博客系统为我们提供的模版标签
[b]系统标签[/b]
| 标签 |
含义 |
备注 |
| {$host} |
博客网址 |
|
| {$name} |
博客标题 |
|
| {$subname} |
博客副标题 |
|
| {$theme} |
主题名称 |
|
| {$style} |
样式名称 |
|
| {$copyright} |
版权说明 |
|
| {$zblogphp} |
当前Z-BlogPHP版本 |
Z-BlogPHP 1.X XXXXX Build xxxxxx |
| {$zblogphphtml} |
当前Z-BlogPHP版本号(长) |
[code]<a href="http://www.rainbowsoft.org/" title="RainbowSoft Z-BlogPHP" target="_blank">Z-BlogPHP 1.1 Taichi Build 131221</a>[/code] |
| {$zblogphpabbrhtml} |
Z-BlogPHP 带链接 无版本号(短) |
[code]<a href="http://www.zblogcn.com/" title="RainbowSoft Z-BlogPHP" target="_blank">Z-BlogPHP</a>[/code] |
| {$language} |
网站语言 |
zh-CN |
| {$header} |
页面头部变量 |
方便插件插入CSS、JS等脚本或其它META信息,请放在html的</head>标签前 |
| {$footer} |
页面尾部变量 |
方便插件插入JS脚本或其它信息,请放在页面尾部</body>标签前 |
| {$type} |
页面类型 |
页面分为index、category、article、page、author、date、tag。请参考页面判断 |
| {$page} |
当前页面页码 |
适用列表页。文章页等默认为1 |
| {$user} |
当前登录用户 |
请参考用户标签 |
| {$socialcomment} |
社会化评论区 |
如多说评论等,可用于文章页面等 |
| {$cookiespath} |
cookie的路径 |
如将Z-BlogPHP安装在子目录,该路径则为[code]/子目录名[/code] |
| [i]{$path}[/i] |
网站目录物理路径 |
[b]注意:[/b]该路径应仅用于文件读取操作,不应直接输出造成安全隐患 |
[b]分类标签[/b]
在摘要或文章等子模板页面中调用需在标签前加“article.”,如分类ID为:[code]{$article.Category.ID}[/code]
| 标签 |
含义 |
备注 |
| {$category.ID} |
分类ID |
|
| {$category.Name} |
分类名称 |
|
| {$category.Alias} |
分类别名 |
|
| {$category.Url} |
分类链接 |
|
| {$category.Count} |
分类文章数量 |
|
| {$category.Intro} |
分类摘要 |
|
| {$category.Order} |
分类序号 |
|
| {$category.Level} |
分类层级 |
目前支持4层级,0表示顶级,1表示2级,2表示3级,3表示4级 |
| {$category.RootID} |
分类的顶级ID |
顶级ID为0时表示该分类即为一级分类 |
| {$category.ParentID} |
分类的上一级ID |
同上 |
| {$category.Parent} |
[b]分类的上一级类实例[/b] |
[b]注意:[/b]如为顶级分类则其上级类为NULL,在使用前需进行判断。如:
{if $article.Category.Parent}{$article.Category.Parent.Name}{/if} |
| {$category.SubCategorys} |
[b]子分类实例数组[/b] |
[b]注意:[/b]如无子分类则为空,在使用前需进行判断。 |
| {$category.Template} |
分类所用模板 |
默认为index |
| {$category.LogTemplate} |
分类下文章所用模板 |
默认为single |
| {$category.Meta} |
分类扩展数据(php序列化字符串) |
更多请参考扩展标签 |
单独获取分类的信息,例如某分类ID的姓名[code]:{$categorys[分类ID].Name}[/code](缺点:当分类id不存在时,会导致网站页面错误,在使用前需进行判断。)
[b]分页标签[/b]
文章列表相关页面中可用分页标签,如首页等。
| 标签 |
含义 |
备注 |
| {$pagebar.PageBarCount} |
分页长度 |
|
| {$pagebar.PageCount} |
每页显示文章数量 |
|
| {$pagebar.Name} |
分页名称 |
|
| {$pagebar.PageAll} |
总页码数 |
|
| {$pagebar.PageNow} |
当前页码 |
|
| {$pagebar.PageFirst} |
起始页码 |
|
| {$pagebar.PageLast} |
尾页页码 |
|
| {$pagebar.PagePrevious} |
上一页ID |
|
| {$pagebar.PageNext} |
下一页ID |
|
| {$pagebar.prevbutton} |
上一页Url |
<a href=“{$pagebar.prevbutton}”>« 更早的文章</a> |
| {$pagebar.nextbutton} |
下一页Url |
<a href=“{$pagebar.nextbutton}”>之后的文章 »</a> |
| {$pagebar.buttons} |
[b]页码关联数组[/b] |
键名为页码,键值为页码对应的链接。
其中有4个特殊键名[code]‹‹[/code] 、[code]‹[/code]、[code]›[/code]、[code]››[/code]分别代表第一页、上一页、下一页、最后页。
如[code]{$pagebar.buttons[3]}[/code]为第3页链接,[code]{$pagebar.buttons['››']}[/code]为最后一页链接。
[b]注意[/b]:[code]‹[/code]、[code]›[/code]只有当上下页存在时不为空,使用时应注意判别。 |
[b]
文章标签(含独立页面)[/b]
| 标签 |
含义 |
备注 |
| {$article.ID} |
文章ID |
|
| {$article.Title} |
文章标题 |
|
| {$article.Alias} |
文章标题别名 |
未设置则等同于Title |
| {$article.IsTop} |
文章是否置顶 |
|
| {$article.Intro} |
文章摘要 |
|
| {$article.Content} |
文章正文 |
|
| {$article.Url} |
文章链接 |
|
| {$article.Status} |
文章状态 |
|
| {$article.IsLock} |
是否禁止评论 |
|
| {$article.CommNums} |
文章评论数 |
|
| {$article.ViewNums} |
文章浏览数 |
|
| {$article.Time([b]XXX[/b])} |
文章发布时间 |
[b]XXX[/b]具体内容参考时间标签 |
| {$article.Category.[b]XXX[/b]} |
文章分类数据 |
[b]XXX[/b]具体内容参考分类标签 |
| {$article.Author.[b]XXX[/b]} |
文章作者数据 |
[b]XXX[/b]具体内容参考用户标签 |
| {$article.Tags.[b]XXX[/b]} |
文章标签数组 |
[b]XXX[/b]具体内容参考Tag标签,注意$article.Tags是个Tag类实例数组 |
| {$article.Prev.Url} |
上一篇URL |
|
| {$article.Next.Url} |
下一篇URL |
|
| {$article.Prev.Title} |
上一篇标题 |
|
| {$article.Next.Title} |
下一篇标题 |
|
| {$article.Type} |
文章类型 |
0为普通文章,1为普通页面。其它类型还在设计中。 |
文章Tag获取方法
[code]{foreach $article.Tags as $tag}<a href="{$tag.Url}" rel="external nofollow" >{$tag.Name}</a>{/foreach}[/code]
具体{$tag.XXX}内容参考Tag标签。:!:注意,独立页面没有tag元素!
[b]评论标签[/b]
在文章页面中显示评论需先格式化评论数据:
[b]{foreach $comments as $key => $comment}{$comment.XXX}{/foreach}[/b]
具体内容参照下表:
| 标签 |
含义 |
备注 |
| {$comment.ID} |
评论ID |
|
| {$comment.FloorID} |
评论楼号 |
子评论不加入楼号计数,默认为0 |
| {$comment.Level} |
评论层级 |
0表示顶层,1表示2层,2表示3层,3表示4层,大于4层的返回4 |
| {$comment.ParentID} |
评论父ID |
上一层评论ID,自身为顶层则为0 |
| {$comment.RootID} |
评论根ID |
最顶层评论ID,自身为顶层则为0 |
| {$comment.LogID} |
评论所属文章/页面ID |
|
| {$comment.Author.Name} |
评论作者 |
本表仅列出常用的作者相关标签,更多可用标签请参考 用户标签 |
| {$comment.Author.HomePage} |
评论网址 |
|
| {$comment.Author.Email} |
评论邮箱 |
|
| {$comment.Author.Avatar} |
评论头像地址 |
|
| {$comment.Post.Url} |
评论所属文章的链接 |
|
| {$comment.Post.Title} |
评论所属文章的标题 |
|
| {$comment.Content} |
评论正文 |
|
| {$comment.IP} |
评论者IP |
|
| {$comment.Agent} |
评论者客户端信息 |
|
| {$comment.Time([b]XXX[/b])} |
评论发布时间 |
具体时间参考时间标签 |
可以通过以下来循环调用该评论的子评论:
[code]{foreach $comment.Comments as $key => $comment}
{template:comment}
{/foreach}[/code]
[b]用户标签[/b]
当前登录用户信息使用[code]$user[/code],如[code]{$user.Name}[/code],当前登录者的名称
当前页面作者信息使用[code]$author[/code],[code]$author[/code]涉及的标签只可在用户专属页面调用。如:[code]{$author.Name}[/code],显示作者的名称
指定用户信息[code]{$zbp.members[1].xxx}[/code],如[code]{$zbp.members[1].Name}[/code],显示ID为1的用户名称。
| 标签 |
含义 |
备注 |
| {$author.Url} |
用户页面链接 |
|
| {$author.Name} |
用户名 |
|
| {$author.Alias} |
用户别名 |
|
| {$author.StaticName} |
用户静态名 |
存在别名时调用别名,不存在则调用用户名 |
| {$author.Level} |
用户级别 |
数值 |
| {$author.LevelName} |
用户级别名 |
|
| {$author.Email} |
用户邮箱 |
|
| {$author.HomePage} |
用户主页 |
|
| {$author.Intro} |
用户摘要 |
|
| {$author.Avatar} |
用户头像 |
|
| {$author.Articles} |
用户发表文章数 |
|
| {$author.Pages} |
用户创建页面数 |
|
| {$author.Comments} |
用户发表评论数 |
|
| {$author.Uploads} |
用户上传文件数 |
|
[b]模块标签[/b]
一般情况下主题应尽可能使用系统内部的模块管理功能来调用侧栏模块,系统内部内置5个侧栏,分别可以使用[code]{template:sidebar}[/code]、[code]{template:sidebar2}[/code]、[code]{template:sidebar3}[/code]、[code]{template:sidebar4}[/code]、[code]{template:sidebar5}[/code]来直接调用。
如果需要单独调用某一模块内容,请使用以下代码调用:
[code]{module:moduleName}[/code]
系统内置模块调用如下:
| 标签 |
含义 |
备注 |
| {module:navbar} |
导航栏 |
|
| {module:calendar} |
日历 |
系统自动更新 |
| {module:controlpanel} |
控制面板 |
|
| {module:catalog} |
网站分类 |
系统自动更新 |
| {module:searchpanel} |
搜索 |
|
| {module:comments} |
最新留言 |
系统自动更新 |
| {module:archives} |
文章归档 |
系统自动更新 |
| {module:statistics} |
站点信息 |
系统自动更新 |
| {module:favorite} |
网站收藏 |
|
| {module:link} |
友情链接 |
|
| {module:misc} |
图标汇集 |
|
| {module:authors} |
作者列表 |
系统自动更新 |
| {module:previous} |
最近发表 |
系统自动更新 |
| {module:tags} |
Tags列表 |
系统自动更新 |
如果需要控制每个模块的具体输出内容或者单独调用某模块属性,调用标签如下:
| 标签 |
含义 |
备注 |
| {$modules['[b]moduleFileName[/b]'].ID} |
内部ID |
|
| {$modules['[b]moduleFileName[/b]'].Name} |
模块名称 |
|
| {$modules['[b]moduleFileName[/b]'].FileName} |
文件名 |
文件名应是唯一的,如为主题添加模块请以[code]theme_主题ID_filename[/code]命名,同理,如为插件添加模块请以[code]theme_插件ID_filename[/code]命名 |
| {$modules['[b]moduleFileName[/b]'].Content} |
模块内容 |
|
| {$modules['[b]moduleFileName[/b]'].HtmlID} |
htmlID |
|
| {$modules['[b]moduleFileName[/b]'].Type} |
模块类型 |
ul表示列表型,div表示混杂型 |
| {$modules['[b]moduleFileName[/b]'].MaxLi} |
ul类型模块显示的最大列数 |
默认为10。该数值不会影响存储,只会限制前端显示条数 |
| {$modules['[b]moduleFileName[/b]'].Source} |
模块属性 |
system=系统模块,theme=主题模块,plugin=插件模块 |
| {$modules['[b]moduleFileName[/b]'].IsHideTitle} |
是否隐藏标题 |
1表示隐藏,0表示不隐藏,默认不隐藏 |
[code]moduleFileName[/code]就是模块的文件名
[b]
Tag标签[/b]
{$tag}
| 标签 |
含义 |
备注 |
| {$tag.Name} |
标签名 |
|
| {$tag.Url} |
标签链接 |
|
| {$tag.Count} |
标签下文章数 |
|
[b]时间标签[/b]
在模板中获取时间如[code]{$article.Time(XXX)}[/code]、[code]{$comment.Time(XXX)}[/code]等处XXX代表从时间戳标准格式符,使用效果等同于PHP原生函数
[code]date ( $format )[/code]
格式符支持PHP原生函数中所有格式符。
常见时间格式代码如下:
| 标签 |
示例 |
备注 |
| {$article.Time('Y年m月d日')} |
2014年01月01日 |
|
| {$article.Time('Y年m月d日 H:i:s')} |
2014年01月01日 01:02:03 |
有前导零 |
[b]
语言标签[/b]
Z-BlogPHP是支持多语言的,系统语言包文件位于/zb_users/language,从1.4版本开始支持应用也拥有自己的语言,具体请参考LoadLanguage 语言包载入。语言包内容以数组格式存储,根据系统配置或指定加载相应语言包内容。
[b]引用系统语言包标签[/b]
[code]{$lang[msg][name]}[/code]
引用应用语言包标签(1.4以上版本适用)
[code]{$lang[APPID][name]}[/code]
所有可用的语言标签请打开相应的语言包文件进行查看。
扩展标签
Z-blogPHP几乎所有数据表都拥有扩展元数据,即Z-BlogPHP的自定义域机制Meta。Meta中数据以PHP序列化格式数据存储,其调用标签如
[code]{$article.Metas.abc}[/code]
若要添加或设置meta数据请参考使用扩展元数据机制,或使用相关插件如 自定义字段插件。
以上是Z-Blog博客系统的官方标签,大家在使用过程中可参考使用。