zblogPHP判断不同页面的代码
zblogPHP模板制作中,经常需要对不同页面进行判断,从而调取该页面的专用模板,今天莹莹主要想记录一下判断首页、分类页、日志页、标签页、独立页面、作者页面、日期页面的代码及常用调用方法,同时结合以实例。
{if $type=='index'&&$page=='1'} /*首页判断*/ {template:index_default} {elseif $type=='category'} /*分类页判断 {$category.Name} {elseif $type=='article'} /*日志页判断*/ {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}
实例展示:
1、主页第一页调用CMS模板
{template:header}{if $type=='index'&&$page=='1'} {template:post-cms}{else} {template:post-category}{/if} {template:footer}
2、不同页面展示不同的侧栏
{if $type=='index'} {template:sidebar} {elseif $type=='category'} {template:sidebar2} {elseif $type=='article'} {template:sidebar3} {elseif $type=='page'} {template:sidebar4} {else} {template:sidebar5} {/if}
3、日志页和独立页面的判断
{template:header} {if $article.Type==ZC_POST_TYPE_ARTICLE} {template:post-single} {else} {template:post-page} {/if} {template:footer}
4、评论是否开启的判断
{if !$article.IsLock}{template:comments} {/if} {if $article.CommNums>0}评论条数是否大于0{/if}
若您想修改或者自己制作zblog模板,以上基础if判断语句必须牢记,用到的频率是非常高的。