由于公司需求,在phpwind论坛版块列表中需要根据用户发帖数量显示new图标,即每个新注册用户发帖量不足5篇时,这五篇帖子每个标题列表前面都添加一个NEW图标,具体是文字,还是图片都可以。
实现流程:在原有数据查询的基础上关联pw_memberdata取出每个会员的发帖数量 具体代码在thread.php中:
function getFromDB($start, $allowtop) {
list($offset, $limit2, $tpcdb, $R) = $this->getThreadSortWithToppedThread($allowtop, $start);
if ($limit2) {
global $db_datastore;
if ($this->threadSearch->order == 'lastpost' && empty($this->threadSearch->urladd) && perf::checkMemcache() && !$R && $offset < 980) {
//* $threadlist = L::loadClass('threadlist', 'forum');
//* $tmpTpcdb = $threadlist->getThreads($this->fid, $offset, $limit2);
$_cacheService = Perf::gatherCache('pw_threads');
$tmpTpcdb = $_cacheService->getThreadListByForumId($this->fid, $offset, $limit2);
$tpcdb = array_merge((array)$tpcdb,(array)$tmpTpcdb);
} else {
$sqladd = $this->threadSearch->getSqlAdd($allowtop);
$query = $this->db->query("SELECT * FROM pw_threads t LEFT JOIN pw_memberdata pd ON pd.uid=t.authorid WHERE t.fid=" . S::sqlEscape($this->fid) . " $sqladd ORDER BY t.{$this->threadSearch->order} {$this->threadSearch->asc} " . S::sqlLimit($offset, $limit2));
while ($thread = $this->db->fetch_array($query)) {
$tpcdb[] = $thread;//普通主题的
}
$this->db->free_result($query);
$R && $tpcdb = array_reverse($tpcdb);
}
}
return $tpcdb;
}
phpwind论坛帖子列表页的帖子分为普通主题和置顶主题、普通主题。上述数据源为普通主题下列为数据源为置顶主题,也需要做相应改变
function getThreadSortWithToppedThread($allowtop, $start) {
global $count;
$R = 0;
$tpcdb = array();
$asc = $this->threadSearch->asc;
if ($allowtop) {
global $foruminfo,$db_perpage;
$rows = (int)($foruminfo['top2'] + $foruminfo['top1']);
if ($start < $rows) {
$L = (int)min($rows - $start, $db_perpage);
$limit = S::sqlLimit($start,$L);
$offset = 0;
$limit2 = $L == $db_perpage ? '' : $db_perpage - $L;
if ($toptids = trim($foruminfo['topthreads'], ',')) {
$query = $this->db->query("SELECT * FROM pw_threads LEFT JOIN pw_memberdata pd ON pd.uid=pw_threads.authorid WHERE pw_threads.tid IN($toptids) ORDER BY pw_threads.topped DESC,pw_threads.lastpost DESC $limit");
while ($rt = $this->db->fetch_array($query)) {
$tpcdb[] = $rt;
}
$this->db->free_result($query);
}
unset($toptids,$L,$limit);
} else {
list($offset,$limit2,$asc,$R) = getstart($start - $rows, $asc, $count);
}
} else {
list($offset,$limit2,$asc,$R) = getstart($start, $asc, $count);
}
$this->threadSearch->asc = $asc;
return array($offset, $limit2, $tpcdb, $R);
}
红色部分是我添加的内容
然后再模板文件中做出判断,模版文件在template/wind/thread_ maincommon.htm中进行判断
263行
$newImgPath="images/0newPerson.gif";
$path=$thread[postnum]>5 ? '':'<img src="'.$newImgPath.'" align="absmiddle" title="新人贴" alt="新人贴" />';
print <<<EOT
-->
<a href="$thread[tpcurl]" name="readlink" $isNewWindowOpen id="a_ajax_$thread[tid]" class="subject_t f14"> $thread[postnum] $thread[subject] $path</a> $thread[ifmark] $thread[titleadd] $thread[recommendadd]
<!--
EOT;
红色部分同样是我添加的。需要注意的是这只是一个草稿版本,列表分为置顶主题,推荐主题,普通主题,以上针对的是普通主题,其它主题应该道理是一样的。