zblog教程 内容:90

zblog主题插件开发者常用的if判断

  • 查看作者
  • 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+版本生效


    请登录之后再进行评论

    登录
    最新评论
    0U币
    已有2193人浏览, 浏览收益10, 礼物收益0, 打赏收益6, 点赞收益0, 广告收益0, 获得总收益16U币
    也可开通会员全场文章免费看
    免费教程