Discuz!教程之DIY主题模块增加主题随机排序功能
2017-06-14 13:46
399 查看
如图,添加后的效果,Discuz默认规则里面是没有随机排序的,本教程介绍如果添加随机排序:
修改文件 \source\class\block\forum\block_thread.php
1、参考文件有三个修改点,请按照修改点修改。
2、如果您的网站是gbk的,修改前请务必将block_thread.php文件编码格式转成gbk的,否则前台会乱码。
修改点1
找到代码
'orderby' => array( 'title' => 'threadlist_orderby', 'type'=> 'mradio', 'value' => array( array('lastpost', 'threadlist_orderby_lastpost'), array('dateline', 'threadlist_orderby_dateline'), array('replies', 'threadlist_orderby_replies'), array('views', 'threadlist_orderby_views'), array('heats', 'threadlist_orderby_heats'), array('recommends', 'threadlist_orderby_recommends'), ), 'default' => 'lastpost' ),
修改为
'orderby' => array( 'title' => 'threadlist_orderby', 'type'=> 'mradio', 'value' => array( array('lastpost', 'threadlist_orderby_lastpost'), array('dateline', 'threadlist_orderby_dateline'), array('replies', 'threadlist_orderby_replies'), array('views', 'threadlist_orderby_views'), array('heats', 'threadlist_orderby_heats'), array('recommends', 'threadlist_orderby_recommends'), array('rand', '随机排序'), ), 'default' => 'lastpost' ),
修改点2
找到代码
$orderby = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('lastpost','dateline','replies','views','heats','recommends')) ? $parameter['orderby'] : 'lastpost') : 'lastpost';修改为
$orderby = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('lastpost','dateline','replies','views','heats','recommends','rand')) ? $parameter['orderby'] : 'lastpost') : 'lastpost';修改点3
找到代码
$query = DB::query("SELECT DISTINCT t.*$sqlfield FROM `".DB::table('forum_thread')."` t $sqlfrom WHERE {$maxwhere}t.readperm='0' $sql AND t.displayorder>='0' ORDER BY t.$orderby DESC LIMIT $startrow,$items;" );修改为
if($orderby=='rand'){
$query = DB::query("SELECT DISTINCT t.*$sqlfield
FROM `".DB::table('forum_thread')."` t
$sqlfrom WHERE {$maxwhere}t.readperm='0'
$sql
AND t.displayorder>='0'
ORDER BY rand()
LIMIT $startrow,$items;"
);
}else{
$query = DB::query("SELECT DISTINCT t.*$sqlfield FROM `".DB::table('forum_thread')."` t $sqlfrom WHERE {$maxwhere}t.readperm='0' $sql AND t.displayorder>='0' ORDER BY t.$orderby DESC LIMIT $startrow,$items;" );
}
相关文章推荐
- jsp常用功能模块-JSP实例学习教程
- jsp常用功能模块-JSP实例学习教程
- Discuz!X1.5论坛DIY增加{lastposter}最后回复者调用解读
- [转]Discuz-x DIY教程 DIY 参数详解之[index=x]
- discuz 论坛词语过滤功能,如何只过滤内容,不替换主题
- jsp常用功能模块-JSP实例学习教程
- <软件教程>给MyEclipse 10增加SVN功能
- Linux下Apache安装/增加mod_rewrite模块以启用rewrite功能
- [原创]为Discuz_X1.5增加手机号码登陆功能
- discuz 模块模板标签说明 DIY模块模板语法详解
- Discuz!论坛wap功能模块编码的注射漏洞
- Joomla!扩展制作实例教程-模板展示组件-增加后台上传图片功能 【转】
- Discuz! 7.0 模块调用脚本范例程序 - 主题
- discuz!X DIY模块的自定义开发
- Flex官方快速入门教程翻译之19.Adding_Drag_and_Drop增加拖放功能
- jsp常用功能模块-JSP实例学习教程
- 优化了碰撞检测与回复模块,增加了Sleep功能.
- Discuz!NT代码阅读笔记(6)--从全局看看:各个模块功能摘要(2)
- 详细教程使用jQuery jPlayer插件给你的站点增加视频和音频功能
- DX1.5 home模块的DIY功能分析