Please login or register.

Login with username, password and session length
Advanced search  


Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: Modify Existing PHP code for use with sNews  (Read 5635 times)

Datu Puti

  • Newbie
  • *
  • Karma: 0
  • Posts: 43
Modify Existing PHP code for use with sNews
« on: November 25, 2006, 04:25:37 pm »

HI all,

Love this sNews! i came across a php script that will plug in a random quote every time the browser refreshes. What i want is to use the same code to output a country profile on a daily weekly monthly basis. not every time the browser refreshes.

Here is the code:

/* Config Part --------------------------------------------------------------------------------------------------------------*/

$random = true;                           // if you want random, keep true, set to false if want sequential
$directory = " ";                        //  Webserver path to your quote files with / on end!
$quotefile = "";                                                         //  The Random Quote file
$quotecountfile = "";                                                   //  The Display Quote file (IF SEQUENTIAL!)

/* End of Config Part -------------------------------------------------------------------------------------------------------*/

$quotes = file($directory.$quotefile);
$number = count($quotes);

   $num = rand(0,$number-1);
   $num = file($directory.$quotecountfile);
   $num = $num[0]+1;
   if($num>$number-1){ // If ran out of quotes, start again!
   if (file_exists($directory.$quotecountfile)) {
      $nu = fopen ($directory.$quotecountfile, "w");
   else {
      die("Cant Find $quotecountfile");

// display the quote on the page

echo "$quotes[$num]";

Can it be done? Is it easy to add the requested features?

or does someone know of an existing php script that already does this? reads code including html tags from a single line text file and displays it daily weekly or monthly?

I am doing this website for a non profit entity and of course as we all know non profits are on tight budgets but need exposure to increase donations etc..

Thnx guys..

Love sNews! Viva sNews!
Regards from the beautiful 7000 Islands of the Philippines! Mabuhay!


  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
Logged - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version


  • Newbie
  • *
  • Karma: 2
  • Posts: 18
  • G'day!
    • ozwebfx
Re: Modify Existing PHP code for use with sNews
« Reply #2 on: December 05, 2007, 03:29:20 am »


I'm also trying to use the same script which is from:

I haven't made any modifications but it doesn't work on my site, the page takes ages to load & it destroys some page formatting .. is anyone using this successfully or does anyone have another random quote script which can be used with sNews 1.6.0 ME?


  • Newbie
  • *
  • Karma: 2
  • Posts: 18
  • G'day!
    • ozwebfx
Re: Modify Existing PHP code for use with sNews
« Reply #3 on: December 05, 2007, 06:01:36 am »

I found this one:

It worked nicely.

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: Modify Existing PHP code for use with sNews
« Reply #4 on: December 05, 2007, 10:17:43 am »

I'm using a super-simple random quote script, found somewhere on the old snews forum ( You can see it in action at

1. random.php
   $quotes[] = '<p>“There’s no problem so big that it can’t be run away from.”</p>
   <p><cite>(Snoopy the dog)</cite></p>';
   $quotes[] = '<p>“Take a cookie. I promise—by the time you’re done eating it, you’ll feel right as rain.”</p>
   <p><cite>(The Oracle)</cite></p>';
   $quotes[] = '<p>“It will grow up to be a quote.”</p>
   <p><cite>(Unknown Genius)</cite></p>';
   $quotes[] = '<p>“Everything in this book may be wrong.”</p>
   <p><cite>(Richard Bach)</cite></p>';

    srand ((double) microtime() * 1000000);
    $randomquote = rand(0,count($quotes)-1);
Save in a file and name it, for example, random.php
Obvious note: change the actual contents, within the single quote marks for each $quotes[] instance.

2. snews.php (you can put this anywhere, I have mine a after breadcrumbs() function.)
function quotes() {
    echo $quotes[$randomquote];

3. index.php
Insert <php quotes(); ?> wherever you want the random text to appear. You can of course use philmoz' Function use mod to put the random thing anywhere.
You can of course use any content within random.php, doesn't have to be text. I've used it for rand om ad blocks, and have thought about using it for random video clips. Anything's possible™. ;)
« Last Edit: December 05, 2007, 10:21:07 am by Fred K (agentsmith) »