SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    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

  2. #2
    SitePoint Member
    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.

  3. #3
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Venetsian View Post
    You want unique picture for every day loaded randomly from a folder then remembered in MySQL database or with already pre-made list?

    Venetsian.
    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

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Iconic_creator View Post
    The images will not be random, each day will have it's own image assigned with a Caption.
    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
    ); 
    check out date() to find out what day it is, then just access $pics[$day]['pic'] and $pics[$day]['caption']

  5. #5
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hash View Post
    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
    ); 
    check out date() to find out what day it is, then just access $pics[$day]['pic'] and $pics[$day]['caption']

    Thanks very much, I really appreciate your help! What I'm cufused about is adding the caption, can you please elaborate further.

    So how do I echo the caption lets say in another div?

    IC

  6. #6
    SitePoint Wizard
    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.

  7. #7
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hash View Post
    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.
    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

  8. #8
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    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.

  9. #9
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SilverBulletUK View Post
    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>

    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" />
    This works for one image but when you start to add additional classes, everything becomes complicated.

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •