Last active
August 29, 2015 13:56
-
-
Save bytefade/b57fc9f85fd2dea08029 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Plugin Rss with thumbnails | |
Plugin URI: | |
Description: Esse plugin é um feed-reader como outro qualquer, porém, ele apresenta também os thumbnails presentes no feed | |
Author: Rodrigo Morbach | |
Version: 1 | |
Author URI: http://www.mundodosaber.com.br/ | |
*/ | |
class PluginRssThumb extends WP_Widget | |
{ | |
function PluginRssThumb() | |
{ | |
$widget_ops = array('classname' => 'RssWithThumbnails', 'description' => 'Apresenta Feed Rss com Thumbnails' ); | |
$this->WP_Widget('RssWithThumbnails', 'Rss With Thumbnail', $widget_ops); | |
} | |
function form($instance) | |
{ | |
$instance = wp_parse_args( (array) $instance, array( 'quantidade' => '' ,'titulo'=>'', 'xml'=>'') ); | |
$title = $instance['quantidade']; | |
$titulo = $instance['titulo']; | |
$xml = $instance['xml']; | |
?> | |
<p><label for="<?php echo $this->get_field_id('quantidade'); ?>">Quantidade de Feeds: <input class="widefat" id="<?php echo $this->get_field_id('quantidade'); ?>" name="<?php echo $this->get_field_name('quantidade'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p> | |
<p><label for="<?php echo $this->get_field_id('titulo'); ?>">Titulo (opcional): <input class="widefat" id="<?php echo $this->get_field_id('titulo'); ?>" name="<?php echo $this->get_field_name('titulo'); ?>" type="text" value="<?php echo attribute_escape($titulo); ?>" /></label></p> | |
<p><label for="<?php echo $this->get_field_id('xml'); ?>">Informe a URL do Feed: <input class="widefat" id="<?php echo $this->get_field_id('xml'); ?>" name="<?php echo $this->get_field_name('xml'); ?>" type="text" value="<?php echo attribute_escape($xml); ?>" /></label></p> | |
<?php | |
} | |
function update($new_instance, $old_instance) | |
{ | |
$instance = $old_instance; | |
$instance['quantidade'] = $new_instance['quantidade']; | |
$instance['titulo'] = $new_instance['titulo']; | |
$instance['xml'] = $new_instance['xml']; | |
return $instance; | |
} | |
function widget($args, $instance) | |
{ | |
extract($args, EXTR_SKIP); | |
$titulo = $instance['titulo']; | |
$xml = $instance['xml']; | |
echo $before_widget; | |
$title = empty($instance['quantidade']) ? ' ' : apply_filters('widget_title', $instance['quantidade']); | |
if (!empty($title)) | |
echo $before_title . $titulo . $after_title; | |
if(empty($xml)){ | |
echo 'Nenhum Feed Encontrado'; | |
} | |
else{ | |
// Codigo do Widget Aqui | |
// echo "<h1>This is my new widget!</h1>"; | |
// $xml=("http://g1.globo.com/dynamo/vestibular-e-educacao/rss2.xml"); | |
$xmlDoc = new DOMDocument(); | |
$xmlDoc->load($xml); | |
//get and output "<item>" elements | |
$x=$xmlDoc->getElementsByTagName('item'); | |
for ($i=0; $i<$instance['quantidade']; $i++)//Define quantas noticias aparecer o na pagina | |
{ | |
// $item_date=$x->item($i)->getElementsByTagName('pubDate')->item(0)->childNodes->item(0)->nodeValue; | |
$item_title=$x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue; | |
$item_link=$x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue; | |
$item_desc=$x->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue; | |
echo '<div class="bg-img-noticia"> | |
<p class="p-titulo-feed">'. $item_title .'</p> | |
<a href=" '. $item_link .' " title="Ler mais: '. $item_title .' " target="_blank"> | |
<p class="p-feed-desc">'.$item_desc.'</p> | |
<img src=" '. get_template_directory_uri() . '/images/14-mais-noticias.png" alt="Ler mais"> | |
</a> | |
</div>'; | |
} | |
} | |
echo $after_widget; | |
} | |
} | |
add_action( 'widgets_init', create_function('', 'return register_widget("PluginRssThumb");') );?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment