loop标签的推荐属性jzattr

来源:官方· 作者 jizhicms· 51次点击 · 7个月前

基本用法

从2.0版本开始,推荐属性就可以自定义多个了,先前1.9.x之前用的 istop,istuijian,ishot也同样有效,最正确的用法是使用 jzattr 进行输出。

后台看推荐属性列表对应的ID,就是推荐属性参数的值。

置顶:1

最热:2

推荐:3


输出置顶内容

{loop table="article" jzattr="1" isshow="1" as="v"}

{/loop}


输出最热内容

{loop table="article" jzattr="2" isshow="1" as="v"}

{/loop}


输出推荐内容

{loop table="article" jzattr="3" isshow="1" as="v"}

{/loop}


输出置顶和最热

{loop table="article" jzattr="1,2" isshow="1" as="v"}

{/loop}


输出非推荐内容

根据 推荐 属性值为 3 ,需要使用sql参数实现

{php
$sql = " (jzattr not like '%,3,%' or jzattr is null) ";
/}
{loop table="article" sql="$sql" isshow="1" limit="10" as="v"}

{/loop}


输出非推荐/置顶内容

根据 推荐 属性值为 3,置顶 属性值为 1 ,需要使用sql参数实现

{php
$sql = " (jzattr not like '%,3,%' or jzattr not like '%,1,%' or jzattr is null) ";
/}
{loop table="article" sql="$sql" isshow="1" limit="10" as="v"}

{/loop}


使用loop输出不同属性标签

{loop table="article" isshow="1" limit="10" as="v"}
    {if($v['jzattr'])}
    {if(strpos($v['jzattr'],',1,')!==false)}置顶{/if}
    {if(strpos($v['jzattr'],',2,')!==false)}最热{/if}
    {if(strpos($v['jzattr'],',3,')!==false)}推荐{/if}
    {/if}
{/loop}


如何判断推荐属性是否有数据?

假设推荐属性置顶 值为1

{php
$isok = M('article')->getCount("jzattr like '%,1,%' and isshow=1");

/}
{if($isok)}
有数据
{else}
没有数据
{/if}


同时判断推荐属性置顶 和 推荐 值为 1 和 3

{php
$isok = M('article')->getCount(" (jzattr like '%,1,%' or jzattr like '%,3,%') and isshow=1");

/}
{if($isok)}
有数据
{else}
没有数据
{/if}


加上栏目ID=1同时判断

{php
$isok = M('article')->getCount("jzattr like '%,1,%' and isshow=1 and tid in(".implode(',',$classtypedata[1]['children']['ids']).")");

/}
{if($isok)}
有数据
{else}
没有数据
{/if}

{php
$isok = M('article')->getCount(" (jzattr like '%,1,%' or jzattr like '%,3,%') and isshow=1 and tid in(".implode(',',$classtypedata[1]['children']['ids']).") ");

/}
{if($isok)}
有数据
{else}
没有数据
{/if}


被收藏 0  ∙  0 赞  
加入收藏
0 回复  
善言善语 (您需要 登录 后才能回复 没有账号 ?)

请先登录网站