Arquivo da tag: twitter

Como criar uma conta no Twitter – Perfil de Pessoa ou Empresa

Link: Como criar uma conta no Twitter – Perfil de Pessoa ou Empresa

Como criar uma conta no Twitter – Perfil de Pessoa ou Empresa http://code.jar.io/como-criar-uma-conta-no-twitter/  #Twitter #MídiasSociais #SocialMedia

Display your favorite tweets with WordPress

Display your favorite tweets with WordPress

Paste this code where you want your favorite tweets to be displayed. Don’t forget to update your favorite feed url on line 3.

< ?php include_once(ABSPATH . WPINC . '/feed.php'); $rss = fetch_feed('http://twitter.com/favorites/793830.rss'); $maxitems = $rss->get_item_quantity(3);
$rss_items = $rss->get_items(0, $maxitems);
?>

Display the Latest Tweet as an Image

Display the Latest Tweet as an Image

A service known as TwitSig is actually capable of reading an account’s tweets and then processing them into an image that can be included in forum signatures, emails, and WordPress templates. This is a great way to show tweets without having their content impact the site’s SEO with major search engines. To do this, simply go to Twitsig.com and sign up according to the website’s instructions.

Then, anywhere within WordPress, add the following code:


Image of Tweets

Create a Page Specifically Used to Display Tweets

Create a Page Specifically Used to Display Tweets

Sometimes, Twitter becomes so central to the success of a website that it deserves its own WordPress page. While this might seem a bit intimidating to accomplish at first, it’s actually very easy. WordPress is simply told to read the Twitter account’s RSS feed and print its content into the page.

To accomplish this, create a new PHP template file called tweets.php and paste the following code into that file:

< ?php /* Template Name: A Page for Tweets */get_header();include_once(ABSPATH.WPINC.'/rss.php'); wp_rss('http://twitter.com/statuses/user_timeline/RSSfilename.rss', 35);get_sidebar(); get_footer();?>

The template above will pull in the existing header, footer, and sidebar, largely completing the site’s design. It will fill that design in with the last 35 tweets that a user posted. Be sure to edit the RSS feed URL to reflect the proper Twitter account before saving the file.

Automatically Create Short URLs for Posts in Tweets

Automatically Create Short URLs for Posts in Tweets

With a simple hack to the theme-specific “functions.php” file, WordPress can automatically generate and display short URLs that are perfect for inclusion in Tweets. This hack uses an existing URL shortening service, and comes in two parts. The first part, placed into the functions file, looks like the example below:

function makeBitly($url) {
$tinyurl = file_get_contents(“http://bit.ly/api-create.php?url=”.$url);
return $bitly;
}

With that new function added to “functions.php,” a second piece of code must be added to the website’s template in order to display the created URL. That line of PHP code must be placed within the WordPress Loop, and it looks like the following:
1

< ?php $burl = makeBitly(get_permalink($post->ID)); echo ‘The short URL for this post: < a href="'.$burl.'" >‘.$burl.’< /a >‘ ? >

Detect Visitors From Twitter

Detect Visitors From Twitter

Much like some websites detect visitors from search engines and greet them in a unique way, Twitter visitors can be automatically detected as well. This is done in almost the exact same manner as search engine detections, using conditional PHP code to check for a visitor’s referral agent and greet them accordingly. here’s how it looks:

< ?php if (strpos("twitter.com",$_SERVER[HTTP_REFERER])==0) { echo "Hey, Twitter enthusiast! We're glad you're here. If you like what you see, be sure to Tweet about it and follow our account!"; } ?>

This code can be placed wherever the greeting should be displayed. Because it is entirely self-contained, there are no modifications necessary to the “functions.php” file or any other files on the FTP server. Only the template files need to be altered.

Display the Latest Tweets from Multiple Authors

Display the Latest Tweets from Multiple Authors

The code mentioned in the above hack can actually be slightly modified so that it can support displaying the latest tweets from multiple users. The modification is rather simple, and still results in a snippet of self-contained PHP code. Place the following lines of code into a template file where the tweets should appear:

< ?php $usernames = "Profile1 Profile2 Profile3 Profile4"; // Usernames go here, separated by a space. $limit = "5"; // Define the maximum number of tweets to show $show = 1; // Change to 0 if account usernames should not be shown, leave set to 1 if they should be $prefix = "Our Latest Tweets"; // A prefix or heading for the tweets $prefix_sub = ""; //Prefix for each individual tweet $wedge = ""; // Separator between tweets $suffix_sub = "
“; // Appended to the end of every tweet
$suffix = “”; // This section of code will be added at the end of the entire list of tweets

function parse_feed($usernames, $limit, $show, $prefix_sub, $wedge, $suffix_sub) {

$usernames = str_replace(” “, “+OR+from%3A”, $usernames);
$feed = “http://search.twitter.com/search.atom?q=from%3A” . $usernames . “&rpp=” . $limit;
$feed = file_get_contents($feed);
$feed = str_replace(“&”, “&”, $feed);
$feed = str_replace(“< ", "<", $feed); $feed = str_replace(">“, “>”, $feed);
$clean = explode(““, $feed);
$amount = count($clean) – 1;

for ($i = 1; $i < = $amount; $i++) {$entry_close = explode("“, $clean[$i]);
$clean_content_1 = explode(““, $entry_close[0]);
$clean_content = explode(“
“, $clean_content_1[1]);
$clean_name_2 = explode(““, $entry_close[0]);
$clean_name_1 = explode(“(“, $clean_name_2[1]);
$clean_name = explode(“)
“, $clean_name_1[1]);
$clean_uri_1 = explode(““, $entry_close[0]);
$clean_uri = explode(“
“, $clean_uri_1[1]);

echo $prefix_sub;

if ($show == 1) { echo “” . $clean_name[0] . “” . $wedge; }
echo $clean_content[0];
echo $suffix_sub;
}
}
echo $prefix;
parse_feed($usernames, $limit, $show, $prefix_sub, $wedge, $suffix_sub);
echo $suffix;
?>

Using the prefixes, the sub-prefixes, and the wedge variable, it’s possible to customize the above code pretty easily and make sure that it fits into any context within in an existing website’s design. Simply list all relevant Twitter usernames, separated by a space, and each will show their latest tweet within the defined limit set in the code.

Display the Latest Tweet on the WordPress Site

Display the Latest Tweet on the WordPress Site

To display the latest tweet anywhere on the WordPress site, including the header, sidebar, footer, or even the main content area, a simple PHP snippet can be used. This code is entirely self-contained, and can be placed directly into a template file. Here’s how it looks:

< ?php $username = "YourTwitterUsername"; // Put your username here. $prefix = "My Latest Tweet"; // Any text that goes before the tweet itself. $suffix = ""; // Any text that should be placed directly after the tweet. $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1";function parse_feed($feed) { $stepOne = explode("“, $feed);
$stepTwo = explode(“”, $stepOne[1]);
$tweet = $stepTwo[0];
$tweet = str_replace(“<“, “< ", $tweet); $tweet = str_replace(">", ">“, $tweet);
return $tweet;
}

$twitterFeed = file_get_contents($feed);
echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);
?>

The PHP snippet above uses the built-in RSS parsing engine that ships with WordPress. It uses the “username” variable to read an account’s RSS feed, and posts the latest tweet in that feed to the website. The prefix and suffix areas allow the tweet to be placed into context, all within the self-contained PHP code.

Display the Website's Total Number of Twitter Followers

Display the Website’s Total Number of Twitter Followers

In order to create an air of popularity, it might be a good idea to show how many people follow the blog’s Twitter account. This method could also be used to show how many people follow a specific author’s account, thereby encouraging new visitors to log on to Twitter and do the same. This involves a relatively long function within the theme-specific functions.php file, as well as a small piece of PHP code in any of the template files where followers should be displayed. The function looks like this example:

function string_getInsertedString($long_string,$short_string,$is_html=false){
if($short_string>=strlen($long_string))return false;
$insertion_length=strlen($long_string)-strlen($short_string);
for($i=0;$isaveHTML();
$element->parentNode->removeChild($element);
$html2=$document->saveHTML();
return string_getInsertedString($html,$html2,true);
}

function getTwitterFollowers($username){
$x = file_get_contents(“http://twitter.com/”.$username);
$doc = new DomDocument;
@$doc->loadHTML($x);
$ele = $doc->getElementById(‘follower_count’);
$innerHTML=preg_replace(‘/^< [^>]*>(.*)< [^>]*>$/’,”1″,DOMElement_getOuterHTML($doc,$ele));
return $innerHTML;
}

With this code placed into the theme-specific functions.php file, a username can be supplied by an external line of PHP code in order to return a specific account’s followers. That’s done by placing the following code into one or more of the current theme’s template files:

We have < ?php echo getTwitterFollowers("YourTwitterUserName")." followers on Twitter"; ?>.

Create a "Tweet This" Button to Be Displayed with Posts

Create a “Tweet This” Button to Be Displayed with Posts

One of the best ways to promote website content and encourage it to go viral is to allow readers to share each post via Twitter. This is done by placing a relatively basic line of code within the standard WordPress Loop, enabling users to create a tweet that automatically links to the post’s permalink. Here’s how it looks in most cases:

Tags Autor
ShortURL: http://code.jar.io/?p=172

Create a "Tweet This" Button to Be Displayed with Posts

Twitter followers count using WordPress transients

Twitter followers count using WordPress transients

Many blogs, including this one, are displaying how many people are following them on Twitter. It’s quite easy to grab some json data, but it takes a significant amount of time. Using transients allow you to grab the json data from Twitter once a day, and store it in your database for future uses.

Simply paste the function below into your functions.php file:

function my_followers_count($screen_name = ‘kovshenin’){
$key = ‘my_followers_count_’ . $screen_name;

// Let’s see if we have a cached version
$followers_count = get_transient($key);
if ($followers_count !== false)
return $followers_count;
else
{
// If there’s no cached version we ask Twitter
$response = wp_remote_get(“http://api.twitter.com/1/users/show.json?screen_name={$screen_name}”);
if (is_wp_error($response))
{
// In case Twitter is down we return the last successful count
return get_option($key);
}
else
{
// If everything’s okay, parse the body and json_decode it
$json = json_decode(wp_remote_retrieve_body($response));
$count = $json->followers_count;

// Store the result in a transient, expires after 1 day
// Also store it as the last successful using update_option
set_transient($key, $count, 60*60*24);
update_option($key, $count);
return $count;
}
}
}

echo “I have ” . my_followers_count(‘kovshenin’) . ” followers”;

Add Twitter and Facebook info fields

Add Twitter and Facebook info fields

By default, WordPress allows you to add various contact info as such as Jabber, AIM and Yahoo Messenger. But there’s no way to add your Twitter and Facebook info. Here’s a handy code snippet to remove the mostly useless YIM, AIM and Jabber and add Twitter and Facebook info instead.

This code goes to your functions.php file.

function new_contactmethods( $contactmethods ) {
$contactmethods[‘twitter’] = ‘Twitter’; // Add Twitter
$contactmethods[‘facebook’] = ‘Facebook’; // Add Facebook
unset($contactmethods[‘yim’]); // Remove YIM
unset($contactmethods[‘aim’]); // Remove AIM
unset($contactmethods[‘jabber’]); // Remove Jabber

return $contactmethods;
}
add_filter(‘user_contactmethods’,’new_contactmethods’,10,1);