Jump to content

Applying CSS to array in pic of day? Is something that can be done?


iconicCreator

Recommended Posts

With help, I have created a script that output/display a different image everyday.

The problem is I would like to individual CSS styling to each image independently.

 

I could add a CSS class to the out put bein echoed but the will apply to any image being display.

 

Here is the complete code.

 

<?php

$aPictureOfTheDay = array(

    #Sunday

    array(

        'img'    =>    '/images/image.jpg',

        'txt'    =>    'Today is Sunday.'

    ),

    #Monday

    array(

        'img'    =>    '/images/image.jpg',

        'txt'    =>    'Today is Monday.'

    ),

    #Tuesday

    array(

        'img'    =>    '/images/image.jpg',

        'txt'    =>    'Today is Tuesday.'

    ),

    #Wednesday

    array(

        'img'    =>    '/images/image.jpg',

        'txt'    =>    'Today is Wednesday.'

    )

)

?>

<!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 $aPictureOfTheDay[date('w')]['img']; ?>" />

        </div>

        <div id="siteFooter">

            <!-- Message of the day -->

            <p><?php echo $aPictureOfTheDay[date('w')]['txt']; ?></p>

        </div>

    </body>

</html>

 

I have tried many methods but no luck.

 

Can you echo each image independently, in order to apply individual styling?

 

Thanks everyone.

 

IC

Link to comment
Share on other sites

Surely all you need to do is add a class item to your $aPictureOfTheDay array (like you have already done with the 'img' and 'txt' items). Now change this line

<img src="<?php echo $aPictureOfTheDay[date('w')]['img']; ?>" />

 

To

<img src="<?php echo $aPictureOfTheDay[date('w')]['img']; ?>" class="<?php echo $aPictureOfTheDay[date('w')]['class']; ?>" />

 

Or wherever you want your class to be applied to.

Link to comment
Share on other sites

Surely all you need to do is add a class item to your $aPictureOfTheDay array (like you have already done with the 'img' and 'txt' items). Now change this line

<img src="<?php echo $aPictureOfTheDay[date('w')]['img']; ?>" />

 

To

<img src="<?php echo $aPictureOfTheDay[date('w')]['img']; ?>" class="<?php echo $aPictureOfTheDay[date('w')]['class']; ?>" />

 

Or wherever you want your class to be applied to.

 

Thanks very much - so where do I applied the CSS styling to?

I'm assuming the example above is to echo each image individually?

 

IC

Link to comment
Share on other sites

I'm assuming the example above is to echo each image individually?

What do you mean by this? Are you now wanting to display all images within your array regardless of the day?

 

so where do I applied the CSS styling to?

Shouldn't you know that? I dont know what you're wanting to apply your styles I was just giving an example.

 

 

Link to comment
Share on other sites

What do you mean by this? Are you now wanting to display all images within your array regardless of the day?

 

No. My question was applying CSS styling to individual images in the array.

 

Since the array contains a collection of images being echo one at a time each day, I was asking how do I apply CSS to the images.

 

Lets assumed I want Monday image to have a red border and tuesday image to have a green border. All I'm trying to do is apply individual style to the images.

 

I did the following before posting my original question.

 

<img src="<?php echo $aPictureOfTheDay[date('w')]['img']; ?>" class="cssHere" />

 

The problem is - this applied the same styling to all of the images when they are echo on a given day.

 

Anyway, sorry for any confusion and thanks for your help.

 

IC

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.