在 phpwind 論壇的帖子列表頁(thread_run.htm)中,預設不顯示帖子摘要與縮略圖。本教程透過元件調用實現該功能。
thread_run.htm(列表頁主模板)widget_thread.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; #-->
在 <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 為原圖。完成後更新緩存,帖子列表即會顯示摘要與縮略圖。