Randomly display a server-side include?

Morgan19

Registered
I'm working on a plain old .shtml website, with the "fanciest" element being that it uses server-side includes.

Each subpage has a sidebar with an area for a blurb of text with a "Tell me more!"-esque button that links to another page in the site. I'd like to set up a handful of SSIs that each page could then randomly pull from to display in that sidebar. So in the end I'd have the blurbs and button sections saved as sidebar1.htm, sidebar2.htm, and sidebar3.htm, then with some sort of code that tells any given page to randomly pull one of those includes and display it in the sidebar every time a user visits the page or refreshes.

I've done that sort of thing with javascript to randomly display images before, but never with includes. Is there any easy, "normal" HTML way to do that without any crazy coding?

Thanks a bunch,
m19
 
php. All the way, php.

It would be very simple (read: super-silliosly super duper simple -- 3 lines of code, max) -- let me know if php is an option (if it's supported on your server), and I can get you started in the right direction.
 
It should be. I don't think there are any restrictions against it but I'm sorry to say I don't know the first thing about coding in PHP, so it might be a little bumpy unless it really is step-by-step easy.

The only hiccup I can think of is that the site's already built out in HTML/.shtml and will be going live relatively soon, so converting everything to PHP isn't really a path I'd want to go down. Is it just a piece or two that would be PHPified?

m19
 
Yup, insert about 3 lines of php code into the file(s). The file extensions may have to be changed from .html/.shtml to .php, though, as the php parser would need that to pick up the files and parse the php code.

Let me know when it's been approved for php, and then I'll ask you for a code snippet from the HTML that describes the server-side include, and return you a code snippet that you'll simply replace the original snippet with. Oh, and change the file extensions to .php on any file you put the code in.

That should be it!
 
Back
Top