• Hello

    I have a category on my blog called status which is kinda like status updates on facebook or whatever. It is displayed usign the following function:


    function currently() {
    $myposts = get_posts('showposts=1');

    foreach($myposts as $post) :
    setup_postdata($post);
    $timestamp = get_the_time("Y-m-d H:m:s");
    $time = nicetime($timestamp);
    echo "<p id=\"currently\">David " . get_the_content() . " <abbr title=\"" . str_replace(" ", "T", $timestamp) . "\">" . $time . "</abbr></p>";
    endforeach;

    }

    with the function nicetime smply changing the time to xx days ago or whatever


    function nicetime($date)
    {
    if(empty($date)) {
    return "No date provided";
    }

    $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
    $lengths = array("60","60","24","7","4.35","12","10");

    $now = time();
    $unix_date = strtotime($date);

    // check validity of date
    if(empty($unix_date)) {
    return "Bad date";
    }

    // is it future date or past date
    if($now > $unix_date) {
    $difference = $now - $unix_date;
    $tense = "ago";

    } else {
    $difference = $unix_date - $now;
    $tense = "from now";
    }

    for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
    $difference /= $lengths[$j];
    }

    $difference = round($difference);

    if($difference != 1) {
    $periods[$j].= "s";
    }

    return "$difference $periods[$j] {$tense}";
    }

    This all works well with one except. the message stays the say, but the time (xx days ago) changes on every page with the loop on to the latest date to the content in the loop, not the content displayed by the currently function. Does anyone know a) why this is and b) how i ca change it so it display the proper date. Eventually i want that function currently to be bigger to include events stored in a category called performances (im a performer) but i dont want to go on till i can get this resolved.

    thanks in advance

    David

  • The topic ‘get_the_time problem’ is closed to new replies.