YugaTech | Philippines, Technology News & Reviews

Philippines, Technology News & Reviews



WP Date Image Hack

I am posting the simple hack I made with using dynamic images to replace the date entries of my blog. Just follow the short tutorial here to implement the same with your Wordpress blog:

  • Create your own date image template in Photoshop. Make sure that you layout them so that the month, day and year are all distinct from each other and not overlapping. See my example here :
  • Using the ruler guide in Photoshop, slice the template into three parts.
  • You will need to determine the date format you use in your blog. Mine uses day of week, day and month. Now create individual images using the sliced template and name them accordingly. For day of week, the naming convention is mon.gif, tue.gif, … sun.gif; for the day — 1.gif,… 30.gif; for the month — jan.gif, feb.gif,… dec.gif.


  • (Note: If you use full date names, you will need to name your GIF files similarly (i.e. Friday, February 22, 2005 will use “friday.gif”, “february.gif”, “22.gif” and “2005.gif”).
  • Now, we’re ready to hack the WP date function to replace text dates with images. Go to your WP theme folder and look for the post.php file and open it for editing. Note: depending on the WP theme you use, the file could also be index.php.
  • Look for the date function as such:
    < ?php the_time('D, M j') ?>

    You will need to break that into 3 parts like this:

    < ?php the_time('D') ?>
    < ?php the_time('M') ?>
    < ?php the_time('j') ?>

    Now we edit them so the code echos the image equivalent:

    < ?php $d = strtolower(get_the_time('D')); echo ("< img src= 'wp-images/{$d}.gif' > “); ?>
    < ?php $m = strtolower(get_the_time('M')); echo ("< img src= 'wp-images/{$m}.gif' > “); ?>
    < ?php $j = strtolower(get_the_time('j')); echo ("< img src = 'wp-images/{$j}.gif' > “); ?>
  • You will need to check on the date format parameter string if you have a different date format.

I hope that was fairly simple to understand. :D I’m not sure if this hack can be made into a plugin though. Maybe some other time. ;)

David Shea of mezzoblue.com made a simplier version using HTML/CSS. Update: Josh of File Me Away made the same tute for MT.

permalink

Enter your email address:

Related Entries:


    100 Responses to “WP Date Image Hack”


    1. Gravatar Icon mr nice ash replied on Jun 28th, 2005 at 5:29 pm (1)

      wow. just as i thought. yeah. im a newbie but i almost exactly figured out what you have done to came up with your wp-image-date Plugins. You really are a PHP guru. Why not submit your plugin?? and share your package to others… ;)

      master i know how to make some tweaks on wordpress but i dont know php itself. :(

    2. Gravatar Icon AnP replied on Jun 28th, 2005 at 7:43 pm (2)

      cool plug-in!!! did you join Alex King’s contest? :)

      Will install it this week! Great one, Yuga!!! You really deserve all the accolades you have been getting.

    3. Gravatar Icon Fleeb replied on Jun 28th, 2005 at 8:04 pm (3)

      Yup it can be made into a plug-in, I think that add_action function in WP…

    4. Gravatar Icon yuga replied on Jun 29th, 2005 at 1:39 am (4)

      @mr. nice ash

      tehehe… madali lang yan actually. Konting kalikot lang. ;)

      @AnP

      Thanks! Hindi po, late na ako dun tsaka di ko ata kaya yun!

      @Fleeb

      Will look into it, but this one is pretty simple. Yung magiging problem mo dito cguro yung management ng Options as WP-Admin.

    5. Gravatar Icon markku replied on Jun 29th, 2005 at 1:48 am (5)

      Yuga, you can actually do it without hacking the date functions. You just make do with:

      .gif’ >

      and the others in similar ways. That way, upgrading WP won’t kill your nice hack. :)

    6. Gravatar Icon Kates replied on Jun 29th, 2005 at 12:46 pm (6)

      Damo gali sagad sa guam bah. Labay lang ko ah.

    7. Gravatar Icon darksparrow replied on Jun 29th, 2005 at 2:40 pm (7)

      i agree with markku

    8. Gravatar Icon yuga replied on Jun 29th, 2005 at 6:13 pm (8)

      Kates, taga diin ka? Ilongga ka man?

      Thanks markku, darksparrow… will look into it. ;)

    9. Gravatar Icon mr nice ash replied on Jun 30th, 2005 at 8:28 am (9)

      and the wordpress hacks… sikat na talaga master ko.

    10. Gravatar Icon Paul Armstrong replied on Jul 3rd, 2005 at 7:13 am (10)

      Why don’t you just output the text in different spans over a single background image? It really isn’t *standard* anymore to use images for anything that could be displayed with text (like the “Too Cool for IE” badge)

    11. Gravatar Icon Fleeb replied on Jul 3rd, 2005 at 12:00 pm (11)

      @Paul

      Well maybe…

      For one, he may be using a font he really like to use but many don’t have (although this can be compensated with the use of the GD image library, and well, by the use of font-family). Another is the anti-aliased text making it look smoother. And finally, before switching to the use of this images, the “text over background image” was employed before (as it is by default).

    12. Gravatar Icon Jose replied on Jul 3rd, 2005 at 2:33 pm (12)

      I need a little bit of help!!! I was looking for a hack like this so long and I finally founded. I try to use it but seems it’s not even been read. What can be wrong???? I use a different date format but I have checked the strings and they are all right. Please Help me. This hack is awesome!!

    13. Gravatar Icon yuga replied on Jul 3rd, 2005 at 2:53 pm (13)

      @ Paul

      Hi! As fleeb mentioned, that used to be the case here, text over image bg. I got a little bored and wanted to customize the theme a bit different so I made the hack.

      @ Jose

      Please check on the codes. The one I posted above has lots of spaces in between tags esp. between the “

    14. Gravatar Icon Jose replied on Jul 4th, 2005 at 9:49 am (14)

      YAY!!!!! Thnks you SO MUCH!!!!

    15. Gravatar Icon markku replied on Jul 4th, 2005 at 11:30 am (15)

      Yuga, just a clarification. Similar hacks like this was used before in greymatter, that was years ago. I think Derek Powazek even used it in Fray, if my memory is not failing me. ;)

      But for WP, I think you’re the first who shared something about this. To hell with those who take and claim it as their own. ;)

      I suggest you stick a CC or any specific license for anything you share, so they think twice about stealing. ;)

    16. Gravatar Icon mr nice ash replied on Jul 4th, 2005 at 1:02 pm (16)

      master, i found a site wherein same hack is posted the same date that you posted this one. June 28, Tuesday. But i think the other one was a moveable type. Yeah.

    17. Gravatar Icon yuga replied on Jul 4th, 2005 at 1:48 pm (17)

      @ Jose

      Welcome! And nice implementation fo the hack on your blog!

      @ markku

      The copycat claimed he got it from File Me Away, but he failed to notice Josh’s hack was for MT. I actually posted a comment on Josh’s blog about our hacks similarities.

      @ mr. nice ash

      Yes, as I posted in my entry, Josh of File Me Away made the same tute for MovableType almost the same day I did mine. Though due to time zone differences, he actually did his a day later.

    18. Gravatar Icon sarah replied on Jul 18th, 2005 at 3:00 am (18)

      hey yuga naalala mo pa kaya ako.. dati pa ako nakapunta dito kaso strawberryshake.net yung domain ko that time.. ayhoo.. ikaw lang pala makakasagot sa hinahanap kong image date hack hahah!! wala naman kasi sa support ng WP.. buti nalang ginoogle kita! hahahah!!! heheheh!!!!

    19. Gravatar Icon yuga replied on Jul 20th, 2005 at 7:54 am (19)

      Hi Sarah!

      Sorry di ko mashado ma remember eh. bago na rin site mo kaya di ko ma familiarize. Good thing ako hindi mo nakalimutan! ;)

      Glad to be able to help you as well. :)

    20. Gravatar Icon Tomjack replied on Dec 31st, 2005 at 8:12 am (20)

      hello, nice blog

    21. Gravatar Icon John replied on Jan 23rd, 2006 at 9:12 pm (21)

      Hi,

      Its a great hack you have made. I have spent more than half a day with it and for some reason I can only make the current date display.

      Im using WP 1.51.2 and on the template is uses:

      ‘,”); ?>

      the date from this is correct.

      ‘; ?>
      ‘; ?>
      ‘; ?>

      ‘; ?>
      ‘; ?>
      ‘; ?>

      Do you have any idea what i need to change to make the post date show and not the current date.

      Many Thanks

    22. Gravatar Icon yuga replied on Jan 23rd, 2006 at 11:07 pm (22)

      Hi John,

      Did you try and just break the date function ito 3 parts, without the image substitution first? That way, we can see if the function really works just fine with your template.

      If you can leave a link to your blog as well too.

    23. Gravatar Icon Big Willy replied on Mar 9th, 2006 at 12:31 pm (23)

      Finally found some good infomation on the subject.

    24. Gravatar Icon Sally replied on Mar 18th, 2006 at 12:12 am (24)

      I wonder since you mentioned what you did if you know how to make this work for me…Great blog here. have a nice weekend! Sally

    Comments are currently closed.



    hit counter