Wordpress Themes - WP Forum at BFA
Click here to register or to donate.
Auto self-registration is not available here - far too many spammers. This forum has many, many backlinks and because of that there is an intense desire among spammers to drop their links here.

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme » Sidebars & Widgets »

Image rotation PHP script needs a tweak


  #1  
Old Jun 13, 2009, 04:33 PM
paulae's Avatar
paulae
 
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 Jun 14, 2009, 06:52 AM
juggledad's Avatar
juggledad
 
23,576 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 Jun 14, 2009, 07:41 AM
paulae's Avatar
paulae
 
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
Code:
);
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 Jun 14, 2009, 10:49 AM
juggledad's Avatar
juggledad
 
23,576 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 Jun 14, 2009, 10:57 AM
paulae's Avatar
paulae
 
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 Jun 14, 2009, 11:49 AM
juggledad's Avatar
juggledad
 
23,576 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 Jun 14, 2009, 12:03 PM
paulae's Avatar
paulae
 
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 Jun 14, 2009, 01:22 PM
juggledad's Avatar
juggledad
 
23,576 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 Jun 14, 2009, 01:33 PM
paulae's Avatar
paulae
 
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 Jun 14, 2009, 01:41 PM
juggledad's Avatar
juggledad
 
23,576 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

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Specific image rotation on page? blueprairie Header configuration & styling 3 Aug 8, 2009 04:12 PM
My <form> in Page can't find it's .php action script kathryn Atahualpa 3 Wordpress theme 2 Jun 7, 2009 11:08 AM
[SOLVED] Internet explorer v8 post pages not loading, also header rotation image issu bushtool Atahualpa 3 Wordpress theme 11 May 30, 2009 10:32 AM
How to enter a php script bilalasd Excerpts, Read more, Pagination 2 Apr 16, 2009 04:53 PM
How to use export.php script file to save theme changes? Andante New Versions, & Updating 1 Mar 22, 2009 07:36 PM


All times are GMT -6. The time now is 10:20 PM.


Powered by vBulletin® Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.