前面我们已经给大家分享过许多phpcms实用的技巧,今天小编再来分享一下怎么实现列表或者频道页文章有缩略图就显示缩略图、没有的话就显示日期的办法,希望对大家有帮助呢!
实现起来很简单,我们知道thumb字段是存储缩略图的,然后我们加个判断就可以了,我们看代码吧!
用于列表页
{pc:content action="lists" catid="$catid" num="12" order="inputtime DESC" page="$page"}
{loop $data $r}
<div class="row lists marginbottom30">
<div class="col-xs-4">
{if $r[thumb]}
<div class="thumb"><a href="{$r[url]}" target="_blank"><img src="{$r[thumb]}" alt="{$r['title']}" title="{$r['title']}" width="100%" class="img-responsive center-block"></a></div>
{else}
<div class="times text-center">
<span class="f30 cdbai bold">{date('d',$r[inputtime])}</span><span class="f12">{date('Y',$r[inputtime])}年{date('m',$r[inputtime])}月</span>
</div>
{/if}
</div>
<div class="col-xs-8">
<h3><a href="{$r[url]}" target="_blank"{title_style($r[style])}title="{$r[title]}">{$r[title]}</a></h3>
<p class="text-muted">{$r[description]}</p>
</div>
</div>
{/loop}
<div class="row pages f13">
<div class="col-xs-12">{$pages}</div>
</div>
{/pc}
用于频道页
{pc:content action="lists" catid="$catid" num="12" order="inputtime DESC"}
{loop $data $r}
<div class="row lists marginbottom30">
<div class="col-xs-4">
{if $r[thumb]}
<div class="thumb"><a href="{$r[url]}" target="_blank"><img src="{$r[thumb]}" alt="{$r['title']}" title="{$r['title']}" width="100%" class="img-responsive center-block"></a></div>
{else}
<div class="times text-center">
<span class="f30 cdbai bold">{date('d',$r[inputtime])}</span><span class="f12">{date('Y',$r[inputtime])}年{date('m',$r[inputtime])}月</span>
</div>
{/if}
</div>
<div class="col-xs-8">
<h3><a href="{$r[url]}" target="_blank"{title_style($r[style])}title="{$r[title]}">{$r[title]}</a></h3>
<p class="text-muted">{$r[description]}</p>
</div>
</div>
{/loop}
{/pc}
效果如下: