请教一个Discuz X2中的帖子排序模式问题!
时间:2011-09-08
来源:互联网
复制内容到剪贴板
$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)}这样的方式即可调用帖子并排序。代码:
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;
}
现在我自己在forum_post表中加了一个xihuan字段,如何改动上面的代码或者写新代码来调用帖子并可以按xihuan字段中的数值大小来排序帖子?
作者: imshaw 发布时间: 2011-09-08
不知道你是Discuz哪个版本,排序是通过forumpost的第三个参数来控制的建议你把xihuan字段放到forum_thread表这样就不用改代码,直接传递参数xihuan就能排序了,如果在forum_post就需要修改函数里的sql查询语句。
作者: Frears 发布时间: 2011-09-09
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28