Javascript/HTML Help!


(David Lyke) #1

Hello! New user here, and I’ve built my site with RapidWeaver and think I’m finally getting the hang of it. At the top and bottom of my page, I have a banner that I’m generating with the following HTML snippet:
a href=“http://www.example.com/Store/”>
img src=“http://www.example.com/resources/Banners/Banner-3.jpg” width=“600” height=“100” border=“0” alt=“Click here to be taken to the Online Store!”

Ideally, I have several different banner images that I’d like to use featuring different products, so is there a way to use Javascript to create a variable and put it into my code snippet so it pulls a different source at random to display each time a page is loaded? I’ve tried using different snippets I’ve found online and none of them seem to generate properly.

Thank you for your help!
David


(Greg Schneck) #2

If you don’t have “Stacks3” plugin you should consider doing so. Stacks3 uses “stacks” add-ons made by 3rd party developers and there are several stacks that will do exactly what you want.

I have a site that uses both php snippets to do exactly what you ask but I highly suggest Stacks3 instead. You’ll never regret getting it. It opens up so many new things for your site… Everything I do now I try to use stacks.

btw… I personally recommend the stacks providers who allow you to “try before you buy.” Here is just one of many good ones. You can also find many free stacks. If they work for you consider donations. stacks4stacks.com - I say again, there are many good stacks developers out there. Read thru the stacks section of this forum…


(David Lyke) #3

Thanks for the quick reply! I’m open to using stacks, but at this point I have everything else I need for my site ready except for these banners without the use of stacks so far, so I’d like to avoid spending the money on the plug in for what I hope is a simple thing to code. I’m ok if it’s a bit more complicated than using the stack if it saves me $50. Would you be willing to please share a generalized example of your PHP snippet similar to the one I have in the original post?
Thank you!
David


(Greg Schneck) #4

Let me add… when you add php make sure you use “ignore formatting” or “clear formatting” on the snippet so else RW will add style code to it. Also make sure you are not using smart quotes.

When I have trouble adding php snippets the problem is usually due to paths. I don’t know your experience level but remember that php doesn’t use urls like html… you must define relative or absolute “paths.” Ideas only, you may know all that…


(Greg Schneck) #5

This is the rotator php - It will select one of the blurbs below selecting the code between the tilde’s.
<?php
path = _SERVER[‘DOCUMENT_ROOT’];
$path .= “/ad_rotator/ad_rotator_ad_list1.txt”;
$fcontents = join (’’, file ($path));
$s_con = split("~",$fcontents);
$banner_no = rand(0,(count($s_con)-1));
echo $s_con[$banner_no];
?>

This is a SAMPLE text the rotator randomly selects from. It has 4 items in it. CODE YOURS AS NEEDED, LIKELY JUST A IMAGE TAG. THE TILDE’S MUST BE THERE. THEY SEPARATE THE ROTATED ITEMS.
This sample is a thumbnail and a blurb of text below. Warning: the coding needs updated but it works. This text goes in a text file in same dir as the script. As per the path in above code this text file is named “ad_rotator_ad_list1.txt”

<a href="/publications/books/bible_separation.php" target="_top" >
<img src="/a/bible_separation_1.jpg" width="100" height="144" alt="Bible Separation" border="0"></a>
<br><div style="font-family:'arial'; font-size:13px; line-height:14px; color: #777777">
<a href="/publications/books/bible_separation.php" target="_top" >Bible Separation</a></div>
~
<a href="/publications/courses/sowing_reaping_course.php" target="_top" >
<img src="/a/sowing_reaping_1.jpg" width="100" height="144" alt="Sowing and Reaping" border="0"></a>
<br><div style="font-family:'arial'; font-size:13px; line-height:14px; color: #777777;">
<a href="/publications/courses/sowing_reaping_course.php" target="_top" >Sowing and <br />Reaping</a></div>
~
<a href="/publications/books/house_church.php" target="_top" >
<img src="/a/house_church_movement_1.png" width="100" height="144" alt="House Church Movement" border="0"></a>
<br><div style="font-family:'arial'; font-size:13px; line-height:14px; color: #777777">
<a href="/publications/books/house_church.php" target="_top" >The House<br />Church Movement</a></div>
~
<a href="/publications/video/biblical_separatism.php" target="_top" >
<img src="/a/bible_separation_1.jpg" width="100" height="144" alt="Bible Separation" border="0"></a>
<br><div style="font-family:'arial'; font-size:13px; line-height:14px; color: #777777">
<a href="/publications/video/biblical_separatism.php" target="_top" >Bible Separation<br />DVD or eVideo</a></div>

And this is the code that goes on your RW page. Place it where-ever you want to rotator to be.
<?php
path = _SERVER[‘DOCUMENT_ROOT’];
$path .= “/includes/ad_rotator.php”;
include_once($path);
?>


(David Lyke) #6

Thank you so much! I appreciate your help and tips for using the forums. I’ll give it a whirl and let you know how it goes.


(Greg Schneck) #7

Reread what I posted as I made edits.

And again… I recommend Stacks instead… you will not regret getting it.


(system) #8

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.