Grow your CSS skills. Land your dream job.

Image rotation by days of the week?

  • # June 14, 2009 at 12:09 pm

    Hi, I did multiple searches on the forum but i didn’t find any related topics, so please pardon me if this question was asked a lot.

    I have 7 images that I have set for each day of the week, Monday, Tuesday etc for a blog that i’m trying to design. but I think it would be a hassle if i were to use the php made for dates of the month that i found earlier on this site since i have to reassign all images to individual dates. I’m not even sure if php works for blogs because i’m not sure what it is anyway.

    Can anyone guide me? Thanks.

    # June 16, 2009 at 2:15 am

    I would use the php date function for day of the week:

    Code:
    /images/header< ?php echo date('N'); ?>.jpg

    That will output a number representation of the day of the week: 1 (for Monday) through 7 (for Sunday)

    So header1.jpg would be Monday’s header.

    # June 16, 2009 at 3:01 am
    "AshtonSanders" wrote:
    I would use the php date function for day of the week:

    Code:
    /images/header< ?php echo date('N'); ?>.jpg

    That will output a number representation of the day of the week: 1 (for Monday) through 7 (for Sunday)

    So header1.jpg would be Monday’s header.

    Thanks but I do not quite understand this. Where am I suppose to place this code? In the <head></head> area? And is that the only line required? Where would my image source be placed?

    Would this work?

    Code:
    /images/header< ?php echo date{"N"); http://www.linkofimagehere.com>.jpg
    # June 16, 2009 at 3:19 am

    I’m sorry, I’ll simplify:

    Here is basic PHP:

    Code:
    < ?php echo date{"N"); ?>

    This will print out a number between 1 and 7 depending on the day of the week: 1 (for Monday) through 7 (for Sunday)

    In general: this is PHP, so it needs to be on a PHP page (not in a .css file)

    So let’s say here’s the HTML code for my image:

    Code:

    I make an image for each day of the week and name them:
    image1.jpg
    image2.jpg
    image3.jpg
    image4.jpg
    etc…

    Now I can change my HTML code to:

    Code:
    .jpg” />

    And that PHP code will be replaced by a number, completing the call for the image.

    (likewise, this can be done in CSS too:

    Code:
    .jpg’)”>

    etc.

    # June 18, 2009 at 2:25 am

    Thank you, it seems plausible, but since I’m using this for a blog i can only use images that are hosted on the net itself, like photobucket, I made several images and labeled them with numbers as you suggested but I do not think the code would work like this,

    Code:
    .jpg” width=”100″ height=”210″ />

    Is it possible to incorporate images from images from the web? or is it strictly to hosted images in our domain only thus it can;t be used on blogs?

    # June 18, 2009 at 9:02 am

    There is a way around this but the best way would be to host your images somewhere.

    Code:
    < ?php

    $dayNo = date{"N");

    If ($dayNo == 1){
    echo "“;
    }
    If ($dayNo == 2){
    echo ““;
    }
    ………

    ?>

    Just keep that going for 7 days.

    Don’t forget to escape the " (speech marks) like " or php will error.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".