1
pcracer
Random HTML Block
  • 2004/2/6 3:23

  • pcracer

  • Just popping in

  • Posts: 31

  • Since: 2003/10/23


Not sure if anyone will find this useful or not...but I use it in a block to display a random image that links to an affillate site that sells PC hardware. I suppose it could be used for any number of things...not sure where I found it, one of the many php script sites?

I created a folder in the root & added my .inc files there.
*Note* Put your html code into a text editor [NotePad] & save as a .inc file.

Create a new custom block & put the code below [update w/your file_name.inc] in & set as php script.
#########################################################

## Put the number of random items to be displayed in place of 5
$items = 5;
$randnum = rand(1,$items);

## This is the path to the files you will be using, leave
## off the trailing slash '/'
$your_path = "/your/path/to/the/items";

## This is the .inc file that will show html in the custom block.
## Only change this part--> _file_name_
## For each item, you add another line, and add 1 to the [#]
$inc[1] = "$your_path/_file_name_.inc";
$inc[2] = "$your_path/_file_name_.inc";
$inc[3] = "$your_path/_file_name_.inc";
$inc[4] = "$your_path/_file_name_.inc";
$inc[5] = "$your_path/_file_name_.inc";

# This places the random html file into the custom block.
include $inc[$randnum];

#########################################################
Good Luck & Enjoy!

2
DobePhat
Re: Random HTML Block
  • 2004/2/6 5:58

  • DobePhat

  • Friend of XOOPS

  • Posts: 656

  • Since: 2003/4/15


Hey , thanks for sharing this...I usualy do it via javascript but that slows things down...

most helpful.
Quick question...so you just use the path as on the server right? and not an absolute url?

Thanks

3
dlh
Re: Random HTML Block
  • 2004/2/6 6:02

  • dlh

  • Posts: 182

  • Since: 2002/2/20


This is great!

Is there a way to set this so that it only pulls up a random include file once per day? Say for features of the day and so forth.

dlh

4
pcracer
Re: Random HTML Block
  • 2004/2/9 23:01

  • pcracer

  • Just popping in

  • Posts: 31

  • Since: 2003/10/23


Quote:
...so you just use the path as on the server right? and not an absolute url?

Use the server path...similar to this $your_path="http://www.zzz.net/rotator" or "../rotator" depends on where you put the folder or how to feed it.


Quote:
Is there a way to set this so that it only pulls up a random include file once per day? Say for features of the day and so forth.


Great Idea!
Add this to the code for it to perform that lil' trick...it should only show the item once per day. [or in a 24 hour span...i think!]

srand(date("mYdjny"));
$randnum = rand(1,$items);
srand(time());



5
Dave_L
Re: Random HTML Block
  • 2004/2/10 1:01

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Wouldn't setting the block's Cache Lifetime to "1 day" also accomplish this?

6
pcracer
Re: Random HTML Block
  • 2004/2/10 11:49

  • pcracer

  • Just popping in

  • Posts: 31

  • Since: 2003/10/23


I never thought of that...

Created another custom block & will test this out too

Login

Who's Online

123 user(s) are online (75 user(s) are browsing Support Forums)


Members: 0


Guests: 123


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Dec 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits