PHPCMS文章列表图文混排显示

PHPCMS文章列表图文混排在模板制作中是比较常见的,也是许多门户站使用频率较多的,在多数站点中,我们经常会看到在首页调用的一列文章,第一条数据是图片,而第二条以及以后都是正常的图片显示,这里提供两种文章列表的混排方法。

第一种是有规则的文章列表混排,看如下代码:

1
2
3
4
5
6
7
8
9
10
11
{pc:content action="lists" catid="$catid" num="10" order="id DESC"}
{loop $data $n $r}
{if $n == 1}
<a href="{$r[url]}"><img src="{thumb($r[thumb],160,200)}" width="160" h
eight="200" alt="{$r[title]}"></a>
{else}{/if}
{if $n == 2,3,4,5}
<a href="{$r[url]}">{$r[title]}</a>
{else}{/if}
{/loop}
{/pc}

通过上面的代码我们可以看出在普通的文章列表里加了一个判断,第一行显示的是图片列表,当然也可以改为图片+文字,而2到5则则是文章列表。

第二种是图文混排列表显示,就是当文章包含有缩略图的时候则图片列表显示,否则则是文章列表显示,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{pc:content action="lists" catid="$catid" num="13" order="id DESC" pa
ge="$page"}
      {loop $data $r}
      {if $r[thumb]}
      <dl>
        <dt><img src="{thumb($r[thumb],248,178)}" height="90" width
="120"></dt>
        <dd style="width:470px; float:left;word-break:break-all;">
          <h2><a href="{$r[url]}" target="_blank" {title_style($r<span class="showmore" title="显示隐藏"><span>▼</span></span>)}>{$r[title]}</a></h2>
          <h5>添加日期:{date('Y-m-d H:i:s',$r[inputtime])} 发
布:{$r[username]}  </h5>
          {str_cut($r[description],220)}</dd>
      </dl>
      {else}
      <dl>
        <dd>
          <h2><a href="{$r[url]}" target="_blank" {title_styl
e($r[style])}>{$r[title]}</a></h2>
          <h5>添加日期:{date('Y-m-d H:i:s',$r[inputtim
e])} 发布:{$r[username]} </h5>
          {str_cut($r[description],500)}...</dd>
      </dl>
      {/if}
      {/loop}
      <div id="pages">{$pages}</div>
      {/pc}

上面的代码中也是图片列表的判断,{if $r[thumb]} 则是判断文章中是否包含有缩略图,其余的代码基本上一致。

posted @ 2015-11-26 16:59  wawa137  阅读(491)  评论(0编辑  收藏  举报