/    Sign up×
Community /Pin to ProfileBookmark

Index page rotation?

Hi,

I was wondering if anyone knew of a way to rotate different home pages each time a user goes to a site? Similar to a rotating banner but a different index page (from a group of say 5) would load each time a user goes to the url.

The reason I am asking is I have a rotating banner working on a page but there is also a list which is in alphabetical order which my client would like so each member on the list has the opportunity to move to the top. As you can probably tell I am not a programmer and based on what I know of their hosting, anything with a database is not an option.

Just curious πŸ™‚ Thanks for any guidance!

to post a comment
JavaScript

6 Comments(s) ↴

Copy linkTweet thisAlerts:
@blah1985Feb 15.2006 β€”Β sure, I will give you a summery, lemme know if you need more detail.

You can do this one of two ways

One:

You can create 6 (or more depending on how many you want) The first page will be a redirect page using top.href=url;

use like Math.round(Math.random()*5) to get the page like

theURL='index'+Math.round(Math.random()*5)+.htm;

then you will redirect to you to the index of your choice.

Two:

Create the content in a document.write(yourvar);

use the random method above to choose which one you want to write.
Copy linkTweet thisAlerts:
@felgallFeb 15.2006 β€”Β That will only select a page at random. To do a proper rotation you need server side processing to keep track of which page in the rotation was last viewed.
Copy linkTweet thisAlerts:
@Wisest_GuyFeb 15.2006 β€”Β You might use this
[code=html]
<SCRIPT LANGUAGE="JavaScript">
PageNum = Math.round(Math.random() * 4) + 1;
if (PageNum != 1)
{document.write('<SCRIPT LANGUAGE="JavaScript">');}
</SCRIPT><!--
/*-->Page 1<!--
*///-->
</SCRIPT><!-- -->
Page 2
[/code]

and so on...
Copy linkTweet thisAlerts:
@blah1985Feb 15.2006 β€”Β ah I c you want SPACIFIC pages. the only way you can do that in JS is with cookies or a log on. just set a cookie and call it. Lemme know if you need more spacific help
Copy linkTweet thisAlerts:
@jmarshallauthorFeb 16.2006 β€”Β Thank you both so much for your response, I appologize for not replying right away I was out of town :-)

Anyway, I am not much of a coder at all so your suggestions are VERY helpful. Basically, I am trying to come up with a solution for the following page which the owner just contacted me about:

http://www.14bestbnbsofnewport.com/

As you can see the list is in alpha order, they would like the list to 'rotate' so that Almondy Inn is not always at the top. My issue is one, I am more of a front-end person (unfortunatley) so writing javascript from scratch is not my thing and two, in reference to any back-end I don't believe their hosting even affords them the opportunity to have a db (it is a small shop out of someones house I think).

So anyway, my thought was ... if I can create 14 different index pages, each having a slightly different list of the Inns that would solve the problem (not the most efficient or technical but I thought it might solve my problem :-)

I will take a further look at below but if you think there might be a better solution, using Javascript please let me know - Thank you SO much!!
Copy linkTweet thisAlerts:
@blah1985Feb 22.2006 β€”Β alright now we are getting somewhere.. First off, PHEW your HTML is sloppy, so I will do an example insead of you code. You want people to see a different order each time right?

well first give each cell an uniuqe ID for example

[code=php]<tr>
<td id="titlecell1">
</td>
</tr>
<tr>
<td id="imagecell1">
</td>
<td id="contentcell1">
</td>
</tr>
<tr>
<td id="informationcell1">
</td>
</tr>
[/code]


leave all of them blank inside, but format them (height,width)

the next step is to build an array that can hold each content peice. MUST ALL BE ON ONE LINE!!

something like


[code=php]var content1 = new Array(
[' Almondy Inn','<img src="something>','Conveniently located in downtown Newport, just steps away from famed Bannister's Wharf. This elegant 1890's Bed and Breakfast has been restored to its original glory and is located within walking distance of Newport's fine restaurants, antique shops, galleries, boutiques and near the various famous Newport Mansions and island beaches.','Evelyne Valkenberg<BR>25 Pelham Street<BR>Newport RI 02840<BR>(800) 478-6155 - (401) 848-7202<BR>http://www.almondyinn.com

email: [email protected]']

);[/code]

these will contain your html for each cell make them for each of your hotels

now you need to write each one of these but ONLY once.

so

set your rand vars
[code=php]var randhold1=0;
var randhold2=0;
var randhold3=0;
var randhold4=0;
var randhold5=0;
var randhold6=0;
var randhold7=0;
var randhold8=0;
var randhold9=0;
var randhold10=0;
var randhold11=0;
var randhold12=0;
var randhold13=0;
var randhold14=0;
//I KNOW there is a better way then this but its late and I cant think..
//Now rand and check for repitition
function intpage()
{
var randhold1=Math.round(Math.random()*13);
while(randhold2==0||randhold2==randhold1)
var randhold2=Math.round(Math.random()*13);
while(randhold3==0||randhold3==randhold1||randhold3==randhold2)
var randhold3=Math.round(Math.random()*13);
while(randhold4==0||randhold4==randhold1||randhold4==randhold2||randhold4==randhold3)
var randhold4=Math.round(Math.random()*13);
//continue this patteren till..
while(randhold14==0||randhold14==randhold1||randhold14==randhold2||randhold14==randhold3||randhold14==randhold4||randhold14==randhold5||randhold14==randhold6||randhold14==randhold7||randhold14==randhold8||randhold14==randhold9||randhold14==randhold10||randhold14==randhold11||randhold14==randhold12||randhold14==randhold13)
var randhold14=Math.round(Math.random()*13);

[/code]

then call your array values and set them to the random value set
[code=php]document.getElementById('titlecell1').innerHTML=eval('content['+randhold1+'][0]');
document.getElementById('imagecell1').innerHTML=eval('content['+randhold1+'][1]');
document.getElementById('contentcell1').innerHTML=eval('content['+randhold1+'][2]');
document.getElementById('informationcell1').innerHTML=eval('content['+randhold1+'][3]');
}
[/code]

follow that trend to the end and your done.

Oh don't forget to add document.onload=intpage();
Γ—

Success!

Help @jmarshall spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 β€” BETA 6.1,
whats_new: community page,
up_next: more Davinciβ€’003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinciβ€’003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...