Discuz!大师网

搜索
查看: 1740|回复: 1

Discuz!教程之实现点击随机访问一个帖子,每次都不一样!

[复制链接]
发表于 2018-1-30 09:26:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

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

  2. define('APPTYPEID', 127);

  3. define('CURSCRIPT', 'rand');

  4. require './source/class/class_core.php';

  5. $discuz = & discuz_core::instance();$discuz->cachelist = $cachelist;$discuz->init();

  6. $tid=DB::result_first("select tid from ".DB::table('forum_thread')." where displayorder>=0 order by rand()");

  7. $url=$_G['siteurl'].'forum.php?mod=viewthread&tid='.$tid;

  8. dheader("location: $url");



  9. ?>
复制代码

然后将rand.php上传至您的论坛根目录(即与forum.php、home.php相同的目录),将http://你的域名/rand.php设置到你要放置的菜单位置!
就能实现如上功能了!

回复 马甲回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|网站地图|小黑屋|展会网|Discuz站长论坛 |天天打卡

GMT+8, 2024-4-25 16:13 , Processed in 0.025620 second(s), 8 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表