Morpheus Posted June 11, 2005 Share Posted June 11, 2005 I've been using this code to show all of my websites banners but it only shows 4 of them. Can someone figure out what's wrong? I'm not very good with Java. [php][/php] Link to comment Share on other sites More sharing options...
Semjaza Posted June 11, 2005 Share Posted June 11, 2005 Are you just trying to display one of these randomly whenever it loads up? If your server can use PHP (I know some free ones can't), there are far better ways to go about this. Link to comment Share on other sites More sharing options...
Morpheus Posted June 11, 2005 Author Share Posted June 11, 2005 Yes, I'm trying to get random banners. I'm not sure if geocities supports php. I will be switching to a paid service soon(most likely Surpass Hosting), so could you explain how to do this in php for the future? Link to comment Share on other sites More sharing options...
wrist cutter Posted June 11, 2005 Share Posted June 11, 2005 If you just want random banners, that's something rather easy to accomplish. [CODE] var pos=Math.floor(Math.random()*(A-1)) var B=new Array(A) B[0] = "C" B[1] = "D" . . . B[A-1] = "E" function getbanner(){ document.write(< IMG SRC=" +B[pos]+">") } [/CODE] A = number of different banners you have. B = name of the array of banners. C...E = the URLs for your banners. Basically this code just picks a random number and creates an array of URLs. When you call the function getbanner() it just writes the code for an image based on the random number it picked earlier. Remember you have to call the function somewhere in your code. This particular script should go somewhere up towards the top. Then when you want your banner inserted, write something like [CODE]getbanner()[/CODE] and you're done. And also note all the code needs to be wrapped with < script > and < /script > tags. Link to comment Share on other sites More sharing options...
Morpheus Posted June 11, 2005 Author Share Posted June 11, 2005 That went in one ear and out the other. I understand, mostly. Can I just C&P the first code and fill in the blanks? Link to comment Share on other sites More sharing options...
Semjaza Posted June 11, 2005 Share Posted June 11, 2005 I use Surpass. Very recommended on my part. If you use PHP in the future, here is the code: [PHP] //Edit this line to the url of your image folder to randomize //Must be a relative URL in your server, do not put in a forward //or trailing slash for it to work. $url='images/banners'; //Stop editing, that is all. Call the image with That's all, enjoy. :D $files=array(); if ($handle=opendir("$url")) { while(false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if(substr($file,-3)=='gif' || substr($file,-3)=='jpg' || substr($file,-3)=='png' || substr($file,-3)=='bmp') $files[count($files)] = $file; } } } closedir($handle); $random=rand(0,count($files)-1); if(substr($files[$random],-3)=='gif') header("Content-type: image/gif"); elseif(substr($files[$random],-3)=='jpg') header("Content-type: image/jpeg"); elseif(substr($files[$random],-3)=='png') header("Content-type: image/png"); elseif(substr($files[$random],-3)=='bmp') header("Content-type: image/bmp"); readfile("$url/$files[$random]"); ?>[/PHP] I don't remember where I got it. The problem with most pre-made scripts you'll find online that do this is that they require you to put in the name of every single last image in there. It's time consuming and obviously increases the file size needlessly. With this one, you just specify the folder and that's the end of it. Just take this code, edit it and put it in "randomimage.php" or whatever you want. Then when you want to use it, just use that php file as the image source. Link to comment Share on other sites More sharing options...
wrist cutter Posted June 12, 2005 Share Posted June 12, 2005 [quote name='Morpheus']Can I just C&P the first code and fill in the blanks?[/quote] Yeah, should be OK as long as everything is filled in right. Oh and be sure to delete the space between the arrow and IMG. Link to comment Share on other sites More sharing options...
Morpheus Posted June 13, 2005 Author Share Posted June 13, 2005 What did I do wrong? [PHP] [/PHP] Link to comment Share on other sites More sharing options...
wrist cutter Posted June 13, 2005 Share Posted June 13, 2005 I've got it working now. [PHP] [/PHP] And then, somewhere in the body of your document, just put: [PHP] [/PHP] I tested this and it worked. Part of the problem was that you had a space in a variable name (Weekly Links I changed to WeeklyLinks), and part of it was my fault. Link to comment Share on other sites More sharing options...
Morpheus Posted June 13, 2005 Author Share Posted June 13, 2005 How do I make them links? Link to comment Share on other sites More sharing options...
wrist cutter Posted June 13, 2005 Share Posted June 13, 2005 Like so: [PHP] [/PHP] That'll show an annoying border on the banners though. Edit the getbanner() function like so: [PHP] function getbanner(){ document.write('') } [/PHP] ...and you'll have a banner that links without a border. Link to comment Share on other sites More sharing options...
Petie Posted June 13, 2005 Share Posted June 13, 2005 [color=blue]You're going to want to include the link tag [url="http://www.otakuboards.com/..."][/url]in the document.write part of the function though. Otherwise, you won't be able to include different sites ads and they will always link to the same place.[/color] Link to comment Share on other sites More sharing options...
wrist cutter Posted June 13, 2005 Share Posted June 13, 2005 [quote name='Petie][color=blue]You're going to want to include the link tag [url="http://www.otakuboards.com/..."][/url']in the document.write part of the function though. Otherwise, you won't be able to include different sites ads and they will always link to the same place.[/color][/quote] That's true. However I believe in this case they're all linking to the same place (all the banners are for the same site). But if they do need to go to different places, I could help there too. Link to comment Share on other sites More sharing options...
Morpheus Posted June 14, 2005 Author Share Posted June 14, 2005 Where does the url go in the borderless code? Link to comment Share on other sites More sharing options...
wrist cutter Posted June 14, 2005 Share Posted June 14, 2005 [quote name='Morpheus']Where does the url go in the borderless code?[/quote] You just put links around the script tags. [PHP] [/PHP] The image will be borderless because of the re-written getbanner() function. The link is still the same old tag. Link to comment Share on other sites More sharing options...
Morpheus Posted June 15, 2005 Author Share Posted June 15, 2005 What's wrong? [PHP] [/PHP] Link to comment Share on other sites More sharing options...
wrist cutter Posted June 15, 2005 Share Posted June 15, 2005 Alright. You have the first part like so: [PHP] [/PHP] It's all OK until the "getbanner()" function. While it will work, you'll get a border. So REPLACE the getbanner() function above with this one: [PHP] function getbanner(){ document.write('') } [/PHP] And that part is good. However, this second part is wrong: [PHP] document.write('') } [/PHP] Here's all you need to put: [PHP] [/PHP] And you'll have a borderless banner that links somewhere on your site. Remember, this second part can go anywhere in your page. It doesn't have to follow the first part of the script at all. Link to comment Share on other sites More sharing options...
jblessing Posted June 15, 2005 Share Posted June 15, 2005 Edit: NVM, already posted. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now