Discuz!教程之DIY主题模块增加主题随机排序功能

159 篇文章 3 订阅
144 篇文章 1 订阅


如图,添加后的效果,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;"
		);			
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
以下是Discuz! X的config_global.php配置文件的注释教程: ```php <?php /** * Discuz! X - 配置文件 * * 版权所有 (C) 2001-2019 Comsenz Inc. * This is NOT a freeware, use is subject to license terms * * $Id: config_global.php 36360 2019-11-18 00:28:51Z nemohou $ */ // ---------------------------- CONFIG DB ----------------------------- // /** * 数据库设置 * * type 数据库类型,可选值为 mysql 或 mysqli * server 数据库服务器 * port 数据库端口 * username 数据库用户名 * password 数据库密码 * dbname 数据库名 * pconnect 是否启用持久连接 * charset 数据库字符集,可选值为 gbk, big5, utf8, latin1, etc. * setnames 是否将字符集强制设为 utf8 * tablepre 表名前缀 * dbdebug 是否启用数据库调试模式 */ $_config['db']['1']['dbtype'] = 'mysql'; $_config['db']['1']['dbhost'] = 'localhost'; $_config['db']['1']['dbport'] = '3306'; $_config['db']['1']['dbuser'] = 'root'; $_config['db']['1']['dbpw'] = 'password'; $_config['db']['1']['dbname'] = 'discuz'; $_config['db']['1']['pconnect'] = '0'; $_config['db']['1']['charset'] = 'utf8'; $_config['db']['1']['setnames'] = '1'; $_config['db']['1']['tablepre'] = 'pre_'; $_config['db']['1']['dbdebug'] = 'false'; // -------------------------- CONFIG MEMORY --------------------------- // /** * 内存变量缓存设置 * * type 缓存类型,可选值为 filecache 或 memcache 或 apc * ttl 缓存失效时间,单位为秒 * prefix 缓存前缀,建议修改,避免同服务器中的程序引起冲突 * servers memcache 缓存服务器地址和端口,可指定多个,格式为数组 */ $_config['memory']['prefix'] = 'discuz_'; $_config['memory']['eaccelerator'] = false; $_config['memory']['apc'] = false; $_config['memory']['xcache'] = false; $_config['memory']['file']['server'] = array(); $_config['memory']['memcache']['server'] = array( array('127.0.0.1', 11211, 1), // 第一个参数为 memcache 服务器的地址,第二个参数为端口,第三个参数为权重,用于负载均衡,默认为1 ); // ----------------------------- CONFIG CACHE --------------------------- // /** * 数据缓存设置 * * type 缓存类型,可选值为 filecache 或 memcache 或 apc * ttl 缓存失效时间,单位为秒 * prefix 缓存前缀,建议修改,避免同服务器中的程序引起冲突 * filecache 设置缓存的目录,仅对 filecache 缓存有效 * servers memcache 缓存服务器地址和端口,可指定多个,格式为数组 * compress 是否启用 memcache 的压缩功能 */ $_config['cache']['type'] = 'filecache'; $_config['cache']['file']['server'] = array( array('localhost', 11211, 1), ); $_config['cache']['memcache']['server'] = array( array('localhost', 11211, 1), ); $_config['cache']['apc'] = false; $_config['cache']['ttl'] = 0; $_config['cache']['prefix'] = 'discuz_'; $_config['cache']['file']['dir'] = './data/cache/'; $_config['cache']['memcache']['compress'] = false; // ----------------------------- CONFIG SMTP --------------------------- // /** * 邮件设置 * * maildefault 默认的邮件发送方式,可选值为 smtp 或 sendmail * smtp 以下 SMTP 设置仅在 maildefault 为 smtp 时有效 * server SMTP 服务器地址 * port SMTP 服务器端口 * auth 是否启用 SMTP 认证,可选值为 true 或 false * username SMTP 服务器用户名 * password SMTP 服务器密码 * sendmail 以下 Sendmail 设置仅在 maildefault 为 sendmail 时有效 * server Sendmail 服务器地址 * sendmail_path Sendmail 程序路径 * * 注意:不同的邮件发送方式对应的设置选项不同,具体请参见官方文档 */ $_config['mail']['maildefault'] = 'smtp'; $_config['mail']['smtp']['server'] = 'smtp.exmail.qq.com'; $_config['mail']['smtp']['port'] = '25'; $_config['mail']['smtp']['auth'] = '1'; $_config['mail']['smtp']['username'] = '[email protected]'; $_config['mail']['smtp']['password'] = 'password'; $_config['mail']['sendmail']['server'] = '/usr/sbin/sendmail'; $_config['mail']['sendmail']['sendmail_path'] = ''; // ----------------------------- CONFIG SECURITY --------------------------- // /** * 安全设置 * * authkey 论坛加密密钥,建议修改,长度为 64 个字符 * cookiepre cookie 前缀,建议修改,避免同服务器中的程序引起冲突 * cachelist 缓存前缀列表,建议修改,避免同服务器中的程序引起冲突 * attackevasive 是否启用防抵制攻击功能,可选值为 0、1、2、3 或 4 * 0 表示关闭防抵制攻击功能 * 1 表示启用 cookie 刷新方式防抵制攻击功能 * 2 表示启用限制代理访问功能防抵制攻击功能 * 3 表示启用 cookie 刷新与限制代理访问两种方式的防抵制攻击功能 * 4 表示启用加强版防抵制攻击功能 * 注意:启用加强版防抵制攻击功能后,可能会影响网站的访问速度 * admincp_allow_ip 允许访问后台的 IP 地址列表,多个 IP 之间用英文逗号隔开 * admincp_check_ip 是否启用后台 IP 验证功能,可选值为 0 或 1 * admincp_cpsession 是否启用后台 session 验证功能,可选值为 0 或 1 */ $_config['security']['authkey'] = '1234567890123456789012345678901234567890123456789012345678901234'; $_config['security']['cookiepre'] = 'discuz_'; $_config['security']['cachelist'] = ''; $_config['security']['attackevasive'] = '0'; $_config['security']['admincp_allow_ip'] = ''; $_config['security']['admincp_check_ip'] = '1'; $_config['security']['admincp_cpsession'] = '1'; // ----------------------------- CONFIG SYSTEM --------------------------- // /** * 系统设置 * * debug 是否启用调试模式,可选值为 true 或 false * cookie_domain cookie 作用域 * cookie_path cookie 作用路径 * attachdir 附件上传目录,相对于论坛根目录的路径 * attachurl 附件 URL 地址 * attachimgpost 是否允许在帖子中显示图片附件,可选值为 0 或 1 * attachrefcheck 是否检查附件引用,可选值为 0 或 1 * attachsave 是否在服务器上保存上传的附件,可选值为 0 或 1 * attachimgmaxsize 图片类附件上传大小,单位为字节 * attachimgthumb 是否生成缩略图,可选值为 0 或 1 * attachimgquality 缩略图质量,取值范围为 1-100 * attachimgwatermark 是否添加水印,可选值为 0 或 1 * attachimgwatermarktype 水印类型,可选值为 text、image 或 none * attachimgwatermarktext 水印文字,当水印类型为 text 时有效 * attachimgwatermarktrans 水印透明度,取值范围为 1-100,当水印类型为 text 时有效 * attachimgwatermarkfile 水印图片文件名,当水印类型为 image 时有效 * attachimgwatermarkpos 水印位置,可选值为 1-9,当水印类型为 image 时有效 * refererhotlink 是否开启防盗链功能,可选值为 0 或 1 * hotlink_protect_key 防盗链密钥,如果不设置,则系统自动生成一个密钥 */ $_config['debug'] = false; $_config['cookie']['cookie_domain'] = ''; $_config['cookie']['cookie_path'] = '/'; $_config['attachdir'] = './data/attachment'; $_config['attachurl'] = 'attachment/'; $_config['attachimgpost'] = '1'; $_config['attachrefcheck'] = '1'; $_config['attachsave'] = '1'; $_config['attachimgmaxsize'] = '2048000'; $_config['attachimgthumb'] = '1'; $_config['attachimgquality'] = '80'; $_config['attachimgwatermark'] = '1'; $_config['attachimgwatermarktype'] = 'text'; $_config['attachimgwatermarktext'] = 'Discuz!'; $_config['attachimgwatermarktrans'] = '50'; $_config['attachimgwatermarkfile'] = ''; $_config['attachimgwatermarkpos'] = '9'; $_config['refererhotlink'] = '0'; $_config['hotlink_protect_key'] = ''; // ----------------------------- CONFIG OUTPUT --------------------------- // /** * 输出设置 * * output_gzip 是否启用 Gzip 压缩输出,可选值为 0 或 1 * output_charset 输出页面字符集,可选值为 gb2312、gbk、big5、utf-8 或 iso-8859-1 * output_language 输出页面语言,可选值为 en、zh-cn、zh-tw * output_encoding 输出页面编码格式,可选值为 xml、html、xhtml */ $_config['output']['gzip'] = '0'; $_config['output']['charset'] = 'utf-8'; $_config['output']['language'] = 'zh-cn'; $_config['output']['encoding'] = 'html'; ``` 以上就是Discuz! X的config_global.php配置文件的注释教程,希望能够帮助到你。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值