displaytweets icon indicating copy to clipboard operation
displaytweets copied to clipboard

Add profile images for account and @replies.

Open joshuaiz opened this issue 11 years ago • 9 comments

Posted this on WordPress.org as well but it would be great to be able to include the Twitter profile image(s) for the main account as well as @replies and have that link to the respective profiles.

I looked through the code and couldn't find a simple way to add it...

joshuaiz avatar Jun 24 '13 00:06 joshuaiz

Should be possible with some custom code. The plugin was developed really for developers, allowing them the freedom to modify things as they wish using the various WordPress actions and filters included within the code.

My blog post regarding the plugin shows how you can overwrite the tweet HTML with your own. The $tweet variable is the JSON response from Twitter, which will include profile image URL, amongst all the other values. You could use this within your own HTML to display each tweet as desired :)

http://matthewruddy.com/display-tweets-plugin/

MatthewRuddy avatar Jun 24 '13 12:06 MatthewRuddy

Hi Matthew,

Thanks for the reply. Yeah I saw the blog post and that should be really easy in theory yet I haven't been able to get any custom html to work properly. Maybe if you could give me a simple example so I can get an idea.

Here is what I was using for the 1.0 API and would like to achieve something similar for Display Tweets:

results; // Valid data now with just the tweet result. // Printing out the feed's data in our required format. if ($valid_data) { ``` foreach ($valid_data as $key=>$value) { print ''; } ``` } else { echo '

Cannot get tweets right now. Please refresh the page or try again later.

'; } Thanks! Joshua On Jun 24, 2013, at 7:40 AM, MatthewRuddy [email protected] wrote: > Should be possible with some custom code. The plugin was developed really for developers, allowing them the freedom to modify things as they wish using the various WordPress actions and filters included within the code. > > My blog post regarding the plugin show how you can overwrite the tweet HTML with your own. The $tweet variable is the JSON response from Twitter, which will include profile image URL, amongst all the other values. You could use this within your own HTML to display each tweet as desired :) > > http://matthewruddy.com/display-tweets-plugin/ > > — > Reply to this email directly or view it on GitHub.

joshuaiz avatar Jun 24 '13 15:06 joshuaiz

It should be as simple as this added to your theme's functions.php file.

function custom_tweet_template( $tweet ) {
    echo "<p>{$tweet->text}</p>";
}
add_action( 'displaytweets_tweet_template', 'custom_tweet_template' );

MatthewRuddy avatar Jun 24 '13 17:06 MatthewRuddy

Thanks Matthew,

I can get that but separating out any of the json data like profile image, hashtags, etc loses all the links even if they are added in that function.

Not really sure how to proceed but thanks for the help.

j

On Jun 24, 2013, at 12:26 PM, MatthewRuddy [email protected] wrote:

It should be as simple as this added to your theme's functions.php file.

function custom_tweet_template( $tweet ) { echo " {$tweet->text}

"; } add_action( 'displaytweets_tweet_template', 'custom_tweet_template' ); — Reply to this email directly or view it on GitHub.

joshuaiz avatar Jun 24 '13 18:06 joshuaiz

If you want to re-add the links, the following preg_replace's should do the trick.

$text = preg_replace( "#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $text );
$text = preg_replace( "#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $text );
$text = preg_replace( "/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $text );
$text = preg_replace( "/#(\w+)/", "<a href=\"http://twitter.com/search?q=%23\\1&src=hash\" target=\"_blank\">#\\1</a>", $text );

MatthewRuddy avatar Jun 24 '13 20:06 MatthewRuddy

Thanks for this but getting an error:

Warning: preg_replace() expects at least 3 parameters, 2 given in /nfs/c02/h05/mnt/43011/domains/uw-mc.org/html/wp-content/themes/uwchilipepper/functions.php on line 262

Where exactly should this go in this function:

function custom_tweet_template( $tweet ) { //custom HTML code here... }

On Jun 24, 2013, at 3:47 PM, MatthewRuddy [email protected] wrote:

$text = preg_replace( "#(^|[\n ])([\w]+?://[\w]+[^ "\n\r\t\2", $text ); $text = preg_replace( "#(^|[\n ])((www|ftp).[^ "\t\n\r\2", $text ); $text = preg_replace( "/@(\w+)/", "@\1", $text ); $text = preg_replace( "/#(\w+)/", "#\1", $text ); return $text;

joshuaiz avatar Jun 24 '13 23:06 joshuaiz

I've just edited the code there now - the syntax highlighting wasn't done correctly so the code wasn't correct either. Sorry about that, try it again now.

MatthewRuddy avatar Jun 25 '13 09:06 MatthewRuddy

Re-download the plugin?

On Jun 25, 2013, at 4:24 AM, MatthewRuddy [email protected] wrote:

I've just edited the code there now - the syntax highlighting wasn't done correctly so the code wasn't correct either. Sorry about that, try it again now.

— Reply to this email directly or view it on GitHub.

joshuaiz avatar Jun 25 '13 14:06 joshuaiz

No no, retry the code from my previous post. It should work if used correctly this time (when you last tried there was a mistake within it):

$text = preg_replace( "#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $text );
$text = preg_replace( "#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $text );
$text = preg_replace( "/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $text );
$text = preg_replace( "/#(\w+)/", "<a href=\"http://twitter.com/search?q=%23\\1&src=hash\" target=\"_blank\">#\\1</a>", $text );

MatthewRuddy avatar Jun 25 '13 14:06 MatthewRuddy