• I’d like to be able use images as headers to my posts, according to which day the post was made. For example, a post made on Monday would have the graphic for Monday as the header and so forth.

    Problem being I’m an absolute PHP noob. After much searching and hacking I’ve been able to get as far as getting an image posted according to the day. However, it looks at todays date and not the date the post was made. Thus all my posts have the same header, regardless of the day they were made and it changes everyday. I told you I was a noob! Here is the code below:

    <?php
    $date=date(“D”);
    if ($date==”Mon”)
    echo'<img src=”images/mon.gif” />’;
    if ($date==”Tue”)
    echo'<img src=”images/tues.gif” />’;
    (and so forth)
    ?>

    My question is how do I get it so the header images corresponds with the day the post was made and stays that way? Any help would be greatly appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • If you made sure to use three letter days for your graphics (i.e. tue.gif instead of tues.gif), you can shorten your code:

    <?php
    $date=strtolower(the_date('D', '', '', false));
    echo "<img src="images/$date.gif" />";
    ?>

    If you want it for all posts, or need to use the_date() to…display the date, try:

    <?php
    $date=strtolower(get_the_time('D'));
    echo "<img src="images/$date.gif" />";
    ?>

    Thread Starter MrM

    (@mrm)

    Hmmm, doesn’t seem to want to work for me. I’m just getting parse errors.

    Whilst playing around I seem to have come slightly closer. I tried the following:

    <?php
    $date=the_time(“D”);
    if ($date==”Mon”)
    echo'<img src=”/images/mon.gif” />’;
    (repeat for the rest of the week)
    ?> (I will use your recommendation about shortening the code Kafka, thank you)

    I’m now getting the day the post was created being outputted but not the corresponding image file. So I’m just ‘Mon’ in the header instead of mon.gif…anybody know why?

    $date=get_the_time('D')

    the_time() will display the info (which makes it difficult to assign to a variable), where get_the_time() merely returns it.

    Thread Starter MrM

    (@mrm)

    AAahhh, it was” $date=get_the_time(“D”);” like Kafka said, not “$date=the_time(“D”);” like the PHP noob MrM said!

    Edit: beat to it! Thank you for your help.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Headers for posts?’ is closed to new replies.