+ -
当前位置:首页 → 问答吧 → 请教一个Discuz X2中的帖子排序模式问题!

请教一个Discuz X2中的帖子排序模式问题!

时间:2011-09-08

来源:互联网

复制内容到剪贴板
代码:
function forumpost($fid,$num,$orderby,$messagenum,$typeid=0,$sortid=0){
$manylist=array();
require_once libfile('function/post');
if($typeid){
$typeadd=" and t.typeid in ($typeid)";
}
if($sortid){
$sortadd=" and t.sortid in ($sortid)";
}
$rs=DB::query("
SELECT t.*,p.message,p.pid,f.name
FROM ".DB::table("forum_thread")." t
LEFT JOIN ".DB::table("forum_post")." p on p.tid=t.tid
LEFT JOIN ".DB::table("forum_forum")." f on f.fid=t.fid
WHERE t.`fid` in ($fid) $typeadd $sortadd and t.displayorder>=0 and p.first=1
group by t.tid
ORDER BY t.`$orderby` DESC
LIMIT 0 , $num");
while ($rw=DB::fetch($rs)) {
$rw['lastposterenc']=urlencode($rw['lastposter']);
$rw['message']=messagecutstr($rw['message'],$messagenum,'');
$rw['message']=dhtmlspecialchars($rw['message']);
$manylist[]=$rw;
}
return $manylist;
}
上面是Discuz中的一段帖子调用代码,在模版中以{eval $list=forumpost('3,4,17,19,29,35',10,'views',280,0,0)}这样的方式即可调用帖子并排序。
现在我自己在forum_post表中加了一个xihuan字段,如何改动上面的代码或者写新代码来调用帖子并可以按xihuan字段中的数值大小来排序帖子?

作者: imshaw   发布时间: 2011-09-08

不知道你是Discuz哪个版本,排序是通过forumpost的第三个参数来控制的建议你把xihuan字段放到forum_thread表这样就不用改代码,直接传递参数xihuan就能排序了,如果在forum_post就需要修改函数里的sql查询语句。

作者: Frears   发布时间: 2011-09-09

热门下载

更多