1 (edited by 2009-09-07 05:56:36)

Topic: [HACK] show random article

Name: show random article
Author: NyNe
CuteNews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Description: Allows you to show a random article on your site. You can limit this article inside a certain category(s)
Instructions:

create a file called show_random.php in the CuteNews root folder and put this in it

<?
// show_random.php
error_reporting (E_ALL ^ E_NOTICE);
$cutepath =  __FILE__;
$cutepath = preg_replace( "'\\\show_random\.php'", "", $cutepath);
$cutepath = preg_replace( "'/show_random\.php'", "", $cutepath);
$news = file($cutepath."data/news.txt");
shuffle($news);
$i = 0;
$newsids = array();
foreach ($news as $news_line) {
$news_arr = explode("|", $news_line);
if (isset($category) && !stristr($category, $news_arr[6])) { continue; }
$newsids[$i] = $news_arr[0];
$i++;
}
$randid = mt_rand(0, count($newsids)-1);
$subaction = "showfull";
$id = $newsids[$randid];
include($cutepath."show_news.php");
?>

then include the file as if it were show_news.php like so

<?
$category = "1,2"; // whatever categories you want (or dont set any)
$template = "Headlines"; // whatever template you want (or dont set one)
include ("/cutepath/show_random.php");
?>


i dont think other variables are really too useful unless you have
hacks installed that use more

NOTE: this will display the full story of whatever article, NOT THE SHORT STORY unless you make a new template for it