zblog主题 / 插件开发会经常用到一些if判断,因此为了方便自己,同时也方便各位开发者使用,我整理了如下判断代码:
判断登入
{if $user.ID>0}
已登录的内容
{else}
未登陆的内容!
{/if}
判断等级
{if $user.Level < 3}
作者等级以上可见
{/if}
{if $user.Level == 3}
只有作者等级可见
{/if}
评论判断
{if $article.CommNums==0}
无评论显示内容
{elseif $article.CommNums==1}
有评论显示内容
{else}
已有{$article.CommNums}条评论
{/if}
判断设备
{if zbp_is_mobile()}
移动端显示内容
{else}
电脑端显示内容
{/if}
PS:只对1.7.2+版本生效
字段判断
{if $xxx}
{$xxx}
{else}
{/if}
PS:当xxx函数存在显示xxx,否则为空
主题判断
{if $type=='index'&&$page=='1'} /*判断首页*/
{template:index_laohan}
{elseif $type=='category'} /*判断分类页*/
{$category.Name}
{elseif $type=='article'} /*判断日志页,不含独立{$article.Title}
{template:index_artile}
{elseif $type=='page'} /*判断独立页面*/
{template:index_page}
{elseif $type=='author'} /*判断用户页*/
{$author.Name}/{$author.StaticName}
{elseif $type=='date'} /*判断日期页*/
date- {$title}
{elseif $type=='tag'} /*判断标签页*/
{$tag.Name}
{else}
{$title}
{/if}
cms主题判断
{if $type=='index'}
{template:c_index}
{elseif $type=='index'&&$page!='1' || $type=='category' || $type=='date'}
{template:list}
{elseif $type=='author'} /*判断用户页*/
{template:author}
{elseif $type=='tag'} /*判断标签页*/
{template:label}
{/if}
置顶判断
{if $article.TopType}置顶{/if}
PS:置顶文章显示
缩图判断
{if $article.AllImages}有缩略图显示{/if}
PS:只对1.7.2+版本生效
广告插入