SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
-
Jun 1, 2009, 16:09 #1
- Join Date
- Aug 2008
- Posts
- 252
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How do I create PHP Pic of the day with a caption?
I'm looking for a PHP script or any help on displaying picture of the day with a caption.
I know a tiny bit of PHP, where do I start? I was looking for a script but have not seen any thing that looks good.
I need to be able to put the caption another area, say the image can display in one area and the caption in another area.
I would love to do this myself but don't know how.
Any ideas, tutorials will be very appreciated.
Thanks everyone.
IC
-
Jun 1, 2009, 16:16 #2
- Join Date
- Jan 2008
- Location
- New York, NY
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You want unique picture for every day loaded randomly from a folder then remembered in MySQL database or with already pre-made list?
Venetsian.
-
Jun 1, 2009, 16:46 #3
- Join Date
- Aug 2008
- Posts
- 252
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I rather not use a data base but rather put the image folder path directly in the script.
The images will not be random, each day will have it's own image assigned with a Caption.
And yes, a unique picture and a caption for each day.
Eg: monday.jpg, tuesday.jpg, ect ect.
Thanks again!
IC
-
Jun 1, 2009, 19:25 #4
- Join Date
- Nov 2005
- Posts
- 1,191
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
if they are pre-defined, just stick the info in an array and select the appropriate one
PHP Code:$pics = array(
'monday' => array('pic' => 'monday.jpg', 'caption' => 'monday image'),
'tuesday' => array('pic' => 'tuesday.jpg', 'caption' => 'tuesday image'),
// etc
);
-
Jun 2, 2009, 05:28 #5
- Join Date
- Aug 2008
- Posts
- 252
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Jun 2, 2009, 05:51 #6
- Join Date
- Nov 2005
- Posts
- 1,191
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You would echo the caption the same way you would echo the pic. I am confused about what you are confused about, otherwise I would gladly elaborate.
-
Jun 2, 2009, 06:53 #7
- Join Date
- Aug 2008
- Posts
- 252
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I understanding echoing the caption and the image.
What I don't know and I very new to PHP, is how do I echo the image in one area of the page and then echo the caption in another section of the page.
Example: The image is in the header of the page and the caption in the footer of the page.
IC
-
Jun 2, 2009, 07:13 #8
- Join Date
- Apr 2008
- Location
- North-East, UK.
- Posts
- 6,111
- Mentioned
- 3 Post(s)
- Tagged
- 0 Thread(s)
Just break out of PHP, then choose to output whatever you require.
PHP Code:<?php
$aPictureOfTheDayCollection = array(
#Sunday
array(
'img' => '/images/image.jpg',
'txt' => 'Some random quote.'
),
#Monday
array(
'img' => '/images/image.jpg',
'txt' => 'Some random quote.'
),
#Tuesday
array(
'img' => '/images/image.jpg',
'txt' => 'Some random quote.'
),
#Wednesday
array(
'img' => '/images/image.jpg',
'txt' => 'Some random quote.'
),
#Thursday
array(
'img' => '/images/image.jpg',
'txt' => 'Some random quote.'
),
#Friday
array(
'img' => '/images/image.jpg',
'txt' => 'Some random quote.'
),
#Saturday
array(
'img' => '/images/image.jpg',
'txt' => 'Some random quote.'
)
)
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div id="siteHeader">
<!-- Image of the day -->
<img src="<?php echo $aPictureOfTheDayCollection[date('w')]['img']; ?>" />
</div>
<div id="siteFooter">
<!-- Message of the day -->
<p><?php echo $aPictureOfTheDayCollection[date('w')]['txt']; ?></p>
</div>
</body>
</html>@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.
-
Jun 3, 2009, 09:32 #9
- Join Date
- Aug 2008
- Posts
- 252
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I worked with the code as directed above an everything appears to be working very well.
However, Since I am using different images, the images does not have fix dimensions. They all have fixed height but not fixed width.
This becomes a problem because I need to position each image independently by assigning a class to the echo string like this.
Code:<img src="<?php echo $aPictureOfTheDayCollection[date('w')]['img']; ?>" class="sunday_image_position" />
So I was wondering if there is a better way to add CSS class to each image being echo, like in the array? I'm not sure how this will work or where to apply the class.
Where can I apply the style to individual image?
Can you echo each image separately?
What's the best or should I say compliant method?
Thanks very much for all your help, time and efforts!
IC
Bookmarks