Basándome en elTwitter Widget para WordPress de Sean Spalding, he modificado ligeramente el código para que muestre únicamente los twitts favoritos de un determinado usuario.
El fuente es éste:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | <?php /* Plugin Name: Twitter Widget Favoritos Plugin URI: http://leccionespracticas.com/php/widget-para-wordpress-mostrar-los-twitts-favoritos-de-tu-cuenta-twitter/ Description: Muestra favoritos de twitter de un usuario (usa Javascript <a href="http://twitter.com/badges/which_badge">Twitter 'badge'</a>) Version: 1.0.0 Author: Miguel Martin Author URI: http://www.leccionespracticas.com License: GPL Basado en: Twitter Widget by Sean Spalding - http://seanys.com/2007/10/12/twitter-wordpress-widget/ This software comes without any warranty, express or otherwise, and if it breaks your blog or results in your cat being shaved, it's not my fault. */ function widget_Twidget_Favoritos_init() { if ( !function_exists('register_sidebar_widget') ) return; function widget_Twidget_Favoritos($args) { // "$args is an array of strings that help widgets to conform to // the active theme: before_widget, before_title, after_widget, // and after_title are the array keys." - These are set up by the theme extract($args); // These are our own options $options = get_option('widget_Twidget'); $account = $options['account']; // Your Twitter account name $title = $options['title']; // Title in sidebar for widget $show = $options['show']; // # of Updates to show // Output echo $before_widget ; // start //echo '<div id="twitter_div">' // .$before_title.$title.$after_title; echo $before_title.$title.$after_title.'<div id="twitter_div">'; echo '<ul id="twitter_update_list"></ul></div> <script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>'; // Con esta linea buscamos TODOS los twitts de el usuario identificado por $account /*echo '<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/'.$account.'.json?callback=twitterCallback2&count='.$show.'"></script>';*/ // Con esta linea buscamos los favoritos del usuario identificado por $account // http://api.twitter.com/1/favorites/bibliouz.json?callback=twitterCallback2&count=5 echo '<script type="text/javascript" src="http://api.twitter.com/1/favorites/'.$account.'.json?callback=twitterCallback2&count='.$show.'"></script>'; // Con esta otra linea se filtra por $account y por $hashtag // http://search.twitter.com/search.json?q=%23HASHTAG+from:USERNAME // similar a (parámetro rpp final es el número de tweets qse muestran // http://search.twitter.com/search?q=&ands=&phrase=&ors=¬s=&tag=bibliotecas&lang=all&from=bibliouz&to=&ref=&near=&within=15&units=mi&since=&until=&rpp=5 //$hashtag = '%23'.'listado'; /*echo '<script type="text/javascript" src="http://search.twitter.com/search.json?q=listado+from:bibliouz"></script>';*/ // echo widget closing tag echo $after_widget; } // Settings form function widget_Twidget_Favoritos_control() { // Get options $options = get_option('widget_Twidget_Favoritos'); // options exist? if not set defaults if ( !is_array($options) ) $options = array('account'=>'seanys', 'title'=>'Twitter Updates', 'show'=>'5'); // form posted? if ( $_POST['Twitter-submit'] ) { // Remember to sanitize and format use input appropriately. $options['account'] = strip_tags(stripslashes($_POST['Twitter-account'])); $options['title'] = strip_tags(stripslashes($_POST['Twitter-title'])); $options['show'] = strip_tags(stripslashes($_POST['Twitter-show'])); update_option('widget_Twidget_Favoritos', $options); } // Get options for form fields to show $account = htmlspecialchars($options['account'], ENT_QUOTES); $title = htmlspecialchars($options['title'], ENT_QUOTES); $show = htmlspecialchars($options['show'], ENT_QUOTES); // The form fields echo '<p style="text-align:right;"> <label for="Twitter-account">' . __('Account:') . ' <input style="width: 200px;" id="Twitter-account" name="Twitter-account" type="text" value="'.$account.'" /> </label></p>'; echo '<p style="text-align:right;"> <label for="Twitter-title">' . __('Title:') . ' <input style="width: 200px;" id="Twitter-title" name="Twitter-title" type="text" value="'.$title.'" /> </label></p>'; echo '<p style="text-align:right;"> <label for="Twitter-show">' . __('Show:') . ' <input style="width: 200px;" id="Twitter-show" name="Twitter-show" type="text" value="'.$show.'" /> </label></p>'; echo '<input type="hidden" id="Twitter-submit" name="Twitter-submit" value="1" />'; } // Register widget for use register_sidebar_widget(array('Twitter-favoritos', 'widgets'), 'widget_Twidget_Favoritos'); // Register settings for use, 300x200 pixel form register_widget_control(array('Twitter-favoritos', 'widgets'), 'widget_Twidget_control', 300, 200); } // Run code and init add_action('widgets_init', 'widget_Twidget_Favoritos_init'); ?> |
Las instrucciones de instalación son de lo más simple:
1. Copiar el archivo superior (twitter-widget-favoritos.php) en /wp-content/plugins/widgets (si no existe la carpeta, la crearemos).
2. Activar el plugin en el menú plugins de wordpress
3. Añadir el widget a la barra lateral en el menú widgets de wordpress y rellenar el menú con el id del usuario (por ejemplo, bibliouz).
Lo he testeado y funciona a la perfección con el tema WP Comfy en wordpress 3.0.4
Podéis consultar La API de favoritos de twitter y la del statuses/user_timeline o a API de búsquedas para más detalles.
Si queréis saber más sobre la creación de widgets para wordpress podéis hacerlo en este sencillo manual
