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

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

时间:2011-09-08

来源:互联网

  1. function forumpost($fid,$num,$orderby,$messagenum,$typeid=0,$sortid=0){
  2. $manylist=array();
  3. require_once libfile('function/post');
  4. if($typeid){
  5. $typeadd=" and t.typeid in ($typeid)";
  6. }
  7. if($sortid){
  8. $sortadd=" and t.sortid in ($sortid)";
  9. }
  10. $rs=DB::query("
  11. SELECT t.*,p.message,p.pid,f.name
  12. FROM ".DB::table("forum_thread")." t
  13. LEFT JOIN ".DB::table("forum_post")." p on p.tid=t.tid
  14. LEFT JOIN ".DB::table("forum_forum")." f on f.fid=t.fid
  15. WHERE t.`fid` in ($fid) $typeadd $sortadd and t.displayorder>=0 and p.first=1
  16. group by t.tid
  17. ORDER BY t.`$orderby` DESC
  18. LIMIT 0 , $num");
  19. while ($rw=DB::fetch($rs)) {
  20. $rw['lastposterenc']=urlencode($rw['lastposter']);
  21. $rw['message']=messagecutstr($rw['message'],$messagenum,'');
  22. $rw['message']=dhtmlspecialchars($rw['message']);
  23. $manylist[]=$rw;
  24. }
  25. return $manylist;
  26. }
复制代码


上面是Discuz中的一段帖子调用代码,在模版中以{eval $list=forumpost('3,4,17,19,29,35',10,'views',280,0,0)}这样的方式即可调用帖子并排序。
现在我自己在forum_post表中加了一个xihuan字段,如何改动上面的代码或者写新代码来调用帖子并可以按xihuan字段中的数值大小来排序帖子?

作者: 萧晔离   发布时间: 2011-09-08



根据你加的字段的顺序,SELECT t.*,p.xihuan,p.message,p.pid,f.name
如果是第18个字段,就直接把$orderby赋值为18就行了

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

相关阅读 更多