WordPress Dates with get_posts()

July 21st, 2009 by Brian
WordPress Dates with get_posts()

One problem that I had when I created the Fro Designs web site was with dates displaying incorrectly when I list my 3 most recent news updates/blog posts at the bottom of the page. For some reason, that date would only be displayed once if there were multiple posts on the same day. This proved to be quite a headache to figure out, but I eventually discovered that the the_date() function works that way.

Fortunately, it was a very simple fix to get the date to show up for each post. All I had to do was swap out the the_date() function and replace it with the the_time() function of WordPress.

Now if you don’t specify the format of the_time() it will actually display the time instead of the date. In order to fix this, you merely need to insert some characters into the brackets of the_time() to tell it how to display the date.

End Result:

<?php the_time('F j, Y'); ?>

This will output the date in this format: Month Day, Year

I’m sure there are other options available, but you just need to find the format that works for you. I hope this post saves other WordPress developers the headache of trying to figure out this quirky problem!

If you enjoyed this article then please share it!

  • email
  • Twitter
  • Digg
  • del.icio.us
  • LinkedIn
  • StumbleUpon
  • Facebook
  • Google Bookmarks
  • Live
  • Reddit
Related Posts
  • It's A New Year Hello Everyone, I would first like to apologize for not updating my site in a while. I've been extremely busy with the holidays and work...
  • Abstract Vector Art This is a tutorial that I found while browsing the popular web design blog called Web Designer Wall. It teaches you how to use Adobe...

Tags:

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)
Loading ... Loading ...

One Response to “WordPress Dates with get_posts()”

  1. vlparrottraining says:

    Nice content indeed! i will visit as often as i can.

    cheers

Leave a Reply