WordPress Date function woe (3 posts)

  1. david
    Posted 12 years ago #

    Can anyone help me to sort out the following code. I would like posts from today to be datestamped "today",. and previous posts to take a date stamp. I wrote the following code which of course doesn't work.

    $today = date("dmy");
    $published = the_time("dmy");
    if($today == $published){?>Today <?}else{?> <?the_time("l")?>, the <?the_time("j")?><?the_time("S")?> of <?the_time("F")?>

    I am going ka ka koo koo. If WP's loop has a variable with just a clean date stamp I think I would use that...but it returns a date and a time, and I don't know how to just strip out the date from that.
    Can anyone come with a solution? I know the root of my problem comes from trying to embed WP functions in my own PHP code.
    I also think it would be nice to have the ability to use relative date/time stamp posts in the same way that textpattern does (for ex. "posted 2 hours ago", "posted 4 days ago", etc) Maybe there are some plug-ins which I just haven't located yet.

  2. codergurl
    Posted 12 years ago #

    $today = date('Y-m-d');
    $pubdate = explode(' ', $post->post_date);
    $pubdate = $pubdate[0];
    if ($pubdate == $today) {
    echo "Today";
    } else {
    the_time('l\,\t\h\e jS \o\f F');

    I had written a hack/plugin to get the years, months, days, etc.., since a while back, and someone editted it. Search in the wiki.

  3. david
    Posted 12 years ago #

    Thanks, the code you wrote is perfect. And the plugin can be located here, should anyone else be interested.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.