WordPress.org

Ready to get started?Download WordPress

Forums

Display Tweets
[resolved] Can date and time be displayed as time since tweet? (8 posts)

  1. rchrisbishop
    Member
    Posted 10 months ago #

    Instead of date and time, can the feed show the minutes, hours or days since the tweet posted?

    http://wordpress.org/extend/plugins/display-tweets-php/

  2. MatthewRuddy
    Member
    Plugin Author

    Posted 10 months ago #

    Going to work on adding this :)

  3. Maligno
    Member
    Posted 10 months ago #

    You can use this function and then on 589 on displaytweets.php
    change:

    $posted_since = apply_filters( 'displaytweets_posted_since', humanTiming(date(strtotime( $tweet->created_at ))) );

    function humanTiming ($time){
    
        $time = time() - $time; // to get the time since that moment
    
        $tokens = array (
            31536000 => 'year',
            2592000 => 'month',
            604800 => 'week',
            86400 => 'day',
            3600 => 'hour',
            60 => 'minute',
            1 => 'second'
        );
    
        foreach ($tokens as $unit => $text) {
            if ($time < $unit) continue;
            $numberOfUnits = floor($time / $unit);
            return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
        }
    }
  4. MatthewRuddy
    Member
    Plugin Author

    Posted 10 months ago #

    Awesome, that's much simpler than what I would have done. Didn't know WordPress had a humanTiming function!

    Thanks a million! :)

  5. rchrisbishop
    Member
    Posted 10 months ago #

    This works, thanks.

  6. MatthewRuddy
    Member
    Plugin Author

    Posted 9 months ago #

    Just to let you's know, in v1.0.3 (just released) I've added an additional filter for modifying the date/time format string. For example, you could do so with the PHP function below.

    function tweet_datetime_string($string) {
        return "l M j \- g:ia";
    }
    add_filter( 'displaytweets_datetime_format', 'tweet_datetime_string' );

    :)

  7. tonyfleming
    Member
    Posted 9 months ago #

    Is it possible to remove the time from the display and display just the date, in DD/MM/YYYY style?

    Thanks!

    EDIT: Worked out how to make this change.

    In displaytweets.php, replace lines 601 with the following:

    /** Set the date and time format */
                    $datetime_format = apply_filters( 'displaytweets_datetime_format', "j F Y" );

    I also wanted to pull the date back up to the previous line to conserve screen space, so replaced line 612 with the following

    echo "<p>{$this->format_tweet( $tweet->text )}<small class=\"muted\">  ({$posted_since})</small></p>";
  8. MatthewRuddy
    Member
    Plugin Author

    Posted 9 months ago #

    Try:

    function tweet_datetime_string($string) {
        return "d/m";
    }
    add_filter( 'displaytweets_datetime_format', 'tweet_datetime_string' );

    Might have to fiddle around with the date/time string yourself. Have a look here for more info.

Reply

You must log in to post.

About this Plugin

About this Topic