|
#1
![Old](images/bytesforall/statusicon/post_old.gif)
Jun 13, 2009, 03:33 PM
|
![paulae's Avatar](image.php?u=372&dateline=1333976845) |
|
|
1,333 posts · Feb 2009
Wordpress 3.4.1, Atahualpa 3.7.7
|
|
This is what I want to do: I want a sidebar image rotation of a different image each day of the month, clicking through to different sponsor for each image. I found a PHP script that does the random image each day part, but I can't figure out how to include the link code for each image. Here is the script that works so far, and if anybody can show me how to put in the URL for each image to link to, I will be so happy! I've put in 2 images to test it. There will be up to 30 eventually. These are pictures of homes for sale, each one linking to an individual real estate agent's website. I tried sticking the URL right after the image code, but that made the whole thing break.
Code:
<?php
$totalPics="2"; // Total photos in folder
$photoOfTheDay = Array ( // Add up to 31 photos below
'1' => '/ads/weichert/0615Mary.jpg' , // Name of or Path to image
'2' => '/ads/weichert/0619Janet.jpg' , // Name of or Path to image
);
// published at: scripts.tropicalpcsolutions.com
// Place day of month in variable 'x'
//$x=date("d");
// A website vistor made a suggestion to change the date function to use j
// instead of d. This causes the date to be read without leading zeros.
$x=date("j"); //Thanks for the suggestion Andrew
// If value of date exceeds the amount of photos then pick a random photo to display
if($x > $totalPics) { $x=rand(1,$totalPics); }
// Display image
echo <<<EOC
<center><img src="$photoOfTheDay[$x]"></center>
EOC;
?>
|
#2
![Old](images/bytesforall/statusicon/post_old.gif)
Jun 14, 2009, 05:52 AM
|
![juggledad's Avatar](image.php?u=675&dateline=1243595674) |
|
|
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
|
|
Paulae,
What you need to do is put the links in an array also. Try this
HTML Code:
<?php
$totalPics="2"; // Total photos in folder
$photoOfTheDay = Array ( // Add up to 31 photos below
'1' => '/ads/weichert/0615Mary.jpg' , // Name of or Path to image
'2' => '/ads/weichert/0619Janet.jpg' , // Name of or Path to image
);
$linkOfTheFDay = Array (
'1' => 'http://www.link1.com' , // Name of or Path to image
'2' => 'http://www.link2.com' , // Name of or Path to image
// published at: scripts.tropicalpcsolutions.com
// Place day of month in variable 'x'
//$x=date("d");
// A website vistor made a suggestion to change the date function to use j
// instead of d. This causes the date to be read without leading zeros.
$x=date("j"); //Thanks for the suggestion Andrew
// If value of date exceeds the amount of photos then pick a random photo to display
if($x > $totalPics) { $x=rand(1,$totalPics); }
// Display image
echo <<<EOC
<center><a href="$linkOfTheDay[$x]"><img src="$photoOfTheDay[$x]"></a></center>
EOC;
?>
Paul
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
|
#3
![Old](images/bytesforall/statusicon/post_old.gif)
Jun 14, 2009, 06:41 AM
|
![paulae's Avatar](image.php?u=372&dateline=1333976845) |
|
|
1,333 posts · Feb 2009
Wordpress 3.4.1, Atahualpa 3.7.7
|
|
Thanks. But that didn't do the trick. At first, I pasted in just what you gave me, and the image disappeared. Then I noticed the was missing after your new array, so I moved it down. That didn't help. So I moved it back after the image array and added one after the link array. Now the image is back but not clickable.
This is what's there now:
Code:
<?php
$totalPics="2"; // Total photos in folder
$photoOfTheDay = Array ( // Add up to 31 photos below
'1' => '/ads/weichert/0615Mary.jpg', // Name of or Path to image
'2' => '/ads/weichert/0619Janet.jpg' , // Name of or Path to image
);
$linkOfTheFDay = Array (
'1' => 'http://www.cnn.com' , // Name of or Path to image
'2' => 'http://www.nytimes.com' , // Name of or Path to image
);
// published at: scripts.tropicalpcsolutions.com
$x=date("j"); //Thanks for the suggestion Andrew
// If value of date exceeds the amount of photos then pick a random photo to display
if($x > $totalPics) { $x=rand(1,$totalPics); }
// Display image
echo <<<EOC
<center><img src="$photoOfTheDay[$x]"></center>
EOC;
?>
|
#4
![Old](images/bytesforall/statusicon/post_old.gif)
Jun 14, 2009, 09:49 AM
|
![juggledad's Avatar](image.php?u=675&dateline=1243595674) |
|
|
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
|
|
Paulae,
I found another typo, the second array is '$linkOfTheFDay'. Get rid of the extra 'F', sigh the problems you get when you don't have your first cup of coffee. Here is the updated version
HTML Code:
<?php
$totalPics="2"; // Total photos in folder
$photoOfTheDay = Array ( // Add up to 31 photos below
'1' => '/ads/weichert/0615Mary.jpg', // Name of or Path to image
'2' => '/ads/weichert/0619Janet.jpg' , // Name of or Path to image
);
$linkOfTheDay = Array (
'1' => 'http://www.cnn.com' , // Name of or Path to image
'2' => 'http://www.nytimes.com' , // Name of or Path to image
);
// published at: scripts.tropicalpcsolutions.com
// Place day of month in variable 'x'
//$x=date("d");
// A website vistor made a suggestion to change the date function to use j
// instead of d. This causes the date to be read without leading zeros.
$x=date("j"); //Thanks for the suggestion Andrew
// If value of date exceeds the amount of photos then pick a random photo to display
if($x > $totalPics) { $x=rand(1,$totalPics); }
$ad_image = '';
$ad_image = '<a href=' . $linkOfTheDay[$x] . '><img src=' . $photoOfTheDay[$x] . '></a>';
// Display image
echo "potd=" . $photoOfTheDay[$x] . "<br>";
echo "lotd=" . $linkOfTheDay[$x] . "<br>";
echo "x=" . $x . "<br>";
echo "<<<EOC <center> " . $ad_image . " </center> EOC" ;
?>
Note the extra 'echo' statements so you can check out the variables, comment them out when your done testing
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
|
#5
![Old](images/bytesforall/statusicon/post_old.gif)
Jun 14, 2009, 09:57 AM
|
![paulae's Avatar](image.php?u=372&dateline=1333976845) |
|
|
1,333 posts · Feb 2009
Wordpress 3.4.1, Atahualpa 3.7.7
|
|
Almost there! By "extra echo statements," you mean which ones?
http://www.larchmontgazette.com
Scroll to the very bottom of the right sidebar. Image is there, link works. Part of the code is showing. I'm not sure which part to comment out.
|
#6
![Old](images/bytesforall/statusicon/post_old.gif)
Jun 14, 2009, 10:49 AM
|
![juggledad's Avatar](image.php?u=675&dateline=1243595674) |
|
|
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
|
|
These three lines
echo "potd=" . $photoOfTheDay[$x] . "<br>";
echo "lotd=" . $linkOfTheDay[$x] . "<br>";
echo "x=" . $x . "<br>";
were just for displaying the variables so I/(you) would know it was working.
You probably want to change the last line from:
echo "<<<EOC <center> " . $ad_image . " </center> EOC" ;
to
echo "<center> " . $ad_image . " </center>" ;
I thought the <<<EOC was something related to a plugin or something
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
|
#7
![Old](images/bytesforall/statusicon/post_old.gif)
Jun 14, 2009, 11:03 AM
|
![paulae's Avatar](image.php?u=372&dateline=1333976845) |
|
|
1,333 posts · Feb 2009
Wordpress 3.4.1, Atahualpa 3.7.7
|
|
OK, that did the trick!
Oddly enough, though, and I don't think this has a thing to do with your work, the image has changed back today to the one from yesterday. It's rotating images more than once a day. Can you see anything in the code that would explain it?
|
#8
![Old](images/bytesforall/statusicon/post_old.gif)
Jun 14, 2009, 12:22 PM
|
![juggledad's Avatar](image.php?u=675&dateline=1243595674) |
|
|
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
|
|
The way the code is written, it gets todays DAY, today is the 14th. It then checks to see if the array has 14 or more images (it doesn't, there are only 2) so it picks a random image from teh array and displays it.
You need an image for the 1st
an image for the 2nd
...
an image for the 31st
then it will stay with that image all day
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
|
#9
![Old](images/bytesforall/statusicon/post_old.gif)
Jun 14, 2009, 12:33 PM
|
![paulae's Avatar](image.php?u=372&dateline=1333976845) |
|
|
1,333 posts · Feb 2009
Wordpress 3.4.1, Atahualpa 3.7.7
|
|
Ah. OK. I'll try putting more images in there.
By the way, I made a donation specifically to you. Thanks for the help!
|
#10
![Old](images/bytesforall/statusicon/post_old.gif)
Jun 14, 2009, 12:41 PM
|
![juggledad's Avatar](image.php?u=675&dateline=1243595674) |
|
|
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
|
|
You're welcome and thanks for the donation!
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
|
|