建站代码网

热门标签

phpcms v9列表页实现文章有图则显示缩略图的方法

phpcms v9列表页实现文章有图则显示缩略图的方法
使用php的if判断:{if $r[thumb]}... ...{/if}
代码示例:
{pc:content action="lists" catid="$catid" num="8" order="id DESC" page="$page"}
<ul id="alist">
{loop $data $r}
<li>
{if $r[thumb]}
<div class="apic"><a href="{$r[url]}"><img src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20480%20640'%3E%3C/svg%3E" loading='lazy' data-lazy-src="http://1.com/skin/default/image/nopic.gif" alt="{$r[title]}" width="170" height="130" /></a></div>
{else}
{/if}
<div class="ablock">
{if $r[thumb]}
<a href="{$r[url]}" class="title" title="{$r[title]}">{str_cut($r[title],47)}</a>
<p class="intro">{str_cut(strip_tags($r[description]), 193)}</p>
{else}
<a href="{$r[url]}" class="title" title="{$r[title]}">{$r[title]}</a>
<p class="intro">{str_cut(strip_tags($r[description]), 188)}</p>
{/if}
<span class="info">
<small class="date">日期:{date('Y-m-d',$r[inputtime])}</small>
{php $keywords = explode(',',$r[keywords]);}
<small class="keywords">关键词:{loop $keywords $keyword}<a href="{APP_PATH}index.php?m=content&c=tag&catid={$catid}&tag={urlencode($keyword)}">{$keyword}</a>{/loop}</small>
</span>
</div>  
</li>
{/loop}
</ul>
<div id="pages" class="pages">{$pages}</div>
{/pc}
X