Discuz!实现点击随机访问一个帖子,每次都不一样! [复制链接]

moqu8 2018-4-16

6 0
最近有站长提到这样的一个需求,系统在菜单中放置一个链接,用户点击这个菜单就能随机访问一个帖子,每次访问的帖子都不一样。如何实现呢?本文分享一下实现方法:
创建一个文件,如:rand.php
写入如下代码

<?php  
define('APPTYPEID', 127);  
define('CURSCRIPT', 'rand');  
require './source/class/class_core.php';  
$discuz = & discuz_core::instance();$discuz->cachelist = $cachelist;$discuz->init();  
$tid=DB::result_first("select tid from ".DB::table('forum_thread')." where displayorder>=0 order by rand()");  
$url=$_G['siteurl'].'forum.php?mod=viewthread&tid='.$tid;  
dheader("location: $url");  
  
?>  
然后将rand.php上传至您的论坛根目录(即与forum.php、home.php相同的目录),将http://你的域名/rand.php设置到你要放置的菜单位置!
最新回复 (0)
返回
支持中心
邮箱:winkill2012@qqcom
新站优化中!部分功能尚未完善,敬请谅解!
支持中心