WordPress.org

Ready to get started?Download WordPress

Forums

Latest Tweets Widget
[resolved] HTML5 time pubdate format? (5 posts)

  1. christianready
    Member
    Posted 11 months ago #

    I am trying to format my Tweets as proper HTML5 <article> elements, e.g.:

    <article>
    <figure><img src="myavatar.jpg></figure>
    <p class="my-tweet">My tweet goes here</p>
    <footer><time pubdate datetime="2013-09-21T09:00:23Z">Sep 21 2013 12:23am</time></footer>

    Does anyone know how would I get the date and time of the tweet into that ISO format for the datetime attribute? Thanks!

    http://wordpress.org/plugins/latest-tweets-widget/

  2. timwhitlock
    Member
    Plugin Author

    Posted 11 months ago #

    See the latest_tweets_render_date filter hook - example in the Other Notes tab.

  3. christianready
    Member
    Posted 11 months ago #

    Thanks. i was looking at that yesterday and I thought I was doing this correctly, but I cannot seem to get a value for the datetime attribute to render. I basically took your example and added an additional filter:

    add_filter('latest_tweets_render_date', function( $created_at ){
    	$datetime = DateTime::createFromFormat('D M d H:i:s O Y', $created_at );
    	return $datetimeX->format('Y-M-d H:i:s');
    }, 10 , 1 );
    
    add_filter('latest_tweets_render_date', function( $created_at ){
    	$date = DateTime::createFromFormat('D M d H:i:s O Y', $created_at );
        return $date->format('d M h:ia');
    }, 10 , 1 );
    
    add_filter('latest_tweets_render_text', function( $text ){
        return $text; // <- will use default
    }, 10 , 1 );
    
    add_filter('latest_tweets_render_tweet', function( $html, $date, $datetimeX, $link, array $tweet ){
        $pic = $tweet['user']['profile_image_url_https'];
        return '<article class="tweet"><figure class="tavatar"><img src="'.$pic.'"></figure><p class="my-tweet">'.$html.'</p><footer class="my-date"><time pubdate datetime="'.$datetimeX.'"><a href="'.$link.'">'.$date.'</a></footer></article>';
    }, 10, 4 );
    
    add_filter('latest_tweets_render_after', function(){
        return '<footer><a href="https://twitter.com/christianready/">More from me</a></footer>';
    }, 10, 0 );

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

    To be on the safe side, I even called the value "datetimeX" in case "datetime" was a reserved word in PHP. The resulting <time> element looks like <time pubdate datetime=""> with no value for the datetime. Any guess as to what I might be doing wrong?

  4. timwhitlock
    Member
    Plugin Author

    Posted 11 months ago #

    there are two mistakes in that code:

    1. you assign $datetime and then attempt to access $datetimeX, which doesn't exist.
    2. You added $datetimeX as an additional argument to latest_tweets_render_tweet. It takes 4 only.

    If you want to write out two separate date values, you'll have to parse and format them again in latest_tweets_render_tweet function.

  5. timwhitlock
    Member
    Plugin Author

    Posted 10 months ago #

    closing after one month with no follow up.

Reply

You must log in to post.

About this Plugin

About this Topic