Return to Snippet

Revision: 52335
at October 20, 2011 08:17 by jhonqwerty


Updated Code
<?php
//replace $options['twitter'] with the twitter Username you want to use.
?>	
		
		<?php
		$xmlfollowersUrl = 'http://api.twitter.com/1/statuses/followers/'.$options['twitter'].'.xml';
		
		if (file_exists(WP_CONTENT_DIR.'/uploads/twitter_followers.xml')) {
		$data = unserialize(file_get_contents(WP_CONTENT_DIR.'/uploads/twitter_followers.xml'));
			if ($data['timestamp'] > time() - 120 * 60) {
			$twitter_followers = $data['twitter_result'];
			}
		}

if (!$twitter_followers) { // cache doesn't exist or is older than 10 mins
    $twitter_followers = file_get_contents($xmlfollowersUrl); // or whatever your API call is

    $data = array ('twitter_followers' => $twitter_followers, 'timestamp' => time());
    file_put_contents(WP_CONTENT_DIR.'/uploads/twitter_followers.xml', serialize($data));
}
		
		
		$dom = new DOMDocument;
		$s = simplexml_load_string($twitter_followers);
		$count = 0;
		echo '<ul class="seguidores">';
		foreach($s->user as $follower):
			if(++$count > 50){
				break;
				}			
			echo '<li><a target="_blank" href="http://www.twitter.com/'.$follower->screen_name.'"><img width="32" height="32" src="'.$follower->profile_image_url.'" alt="'.$follower->name.'" title="'.$follower->name.': '.$follower->status->text.'"/></a></li>';		
		endforeach;
		echo '</ul>';				
		?>

Revision: 52334
at October 20, 2011 07:26 by jhonqwerty


Initial Code
<?php
//replace $options['twitter'] with the twitter Username you want to use.
?>	

<h3><?php print twitter_followers_counter($options['twitter']) ;?> seguidores</h3>
		
		<?php
		$xmlfollowersUrl = 'http://api.twitter.com/1/statuses/followers/'.$options['twitter'].'.xml';
		
		if (file_exists(WP_CONTENT_DIR.'/uploads/twitter_followers.xml')) {
		$data = unserialize(file_get_contents(WP_CONTENT_DIR.'/uploads/twitter_followers.xml'));
			if ($data['timestamp'] > time() - 120 * 60) {
			$twitter_followers = $data['twitter_result'];
			}
		}

if (!$twitter_followers) { // cache doesn't exist or is older than 10 mins
    $twitter_followers = file_get_contents($xmlfollowersUrl); // or whatever your API call is

    $data = array ('twitter_followers' => $twitter_followers, 'timestamp' => time());
    file_put_contents(WP_CONTENT_DIR.'/uploads/twitter_followers.xml', serialize($data));
}
		
		
		$dom = new DOMDocument;
		$s = simplexml_load_string($twitter_followers);
		$count = 0;
		echo '<ul class="seguidores">';
		foreach($s->user as $follower):
			if(++$count > 50){
				break;
				}			
			echo '<li><a target="_blank" href="http://www.twitter.com/'.$follower->screen_name.'"><img width="32" height="32" src="'.$follower->profile_image_url.'" alt="'.$follower->name.'" title="'.$follower->name.': '.$follower->status->text.'"/></a></li>';		
		endforeach;
		echo '</ul>';				
		?>

Initial URL

                                

Initial Description
A simple script to show a followers list in Wordpress. (It can be used in other places also, you have to change the WP specific variables). The script needs to create a cache file to not overload Twitter API.

Initial Title
Twitter Followers Image List

Initial Tags
xml, api, twitter

Initial Language
PHP