萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> CMS 教學

phpwind 論壇:帖子列表調用摘要與縮略圖教程

需求場景

在 phpwind 論壇的帖子列表頁(thread_run.htm)中,預設不顯示帖子摘要與縮略圖。本教程透過元件調用實現該功能。

修改文件

  • thread_run.htm(列表頁主模板)
  • widget_thread.htm(帖子項目子模板)

步驟一:修改 thread_run.htm

找到 <!--# if ($threadList) { #-->,在其下方插入:

<!--# 
$threadtids = array(); 
foreach ($threadList as $value) { 
  $threadtids[] = $value['tid']; 
} 
#-->
<component class='SRV:forum.PwThread' method='fetchThread' args='$threadtids,2'/>
<!--# $threadContent = $__tpl_data; #-->
<component class='SRV:attach.PwThreadAttach' method='fetchAttach' args='$threadtids' />
<!--# $threadthumb = $__tpl_data; #-->

步驟二:修改 widget_thread.htm

在 <p class="info"> 上方加入:

<p class="mb5">
  {@Pw::substrs(Pw::stripWindCode($threadContent[$value['tid']]['content'],true),120)}
  <!--# if ($threadthumb[$value['tid']]['path']['ifthumb']){ #-->
  <div><img src="{@Pw::getPath($threadthumb[$value['tid']]['path'],2)}" /></div>
  <!--# } #-->
</p>

參數說明

  • Pw::substrs(...,120):截取 120 字元摘要,可自行調整長度。
  • Pw::getPath(...,2):獲取縮略圖路徑。參數 2 為縮略圖,1 為大圖,0 為原圖。

完成後更新緩存,帖子列表即會顯示摘要與縮略圖。

copyright © 萬盛學電腦網 all rights reserved