Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Plugin Name: MZ - RSS v2
- Version: 2.0
- Author: Marek Železný
- */
- class mz_RSS_onepost extends WP_Widget
- {
- function mz_RSS_onepost()
- {
- $widget_ops = array('classname' => 'mz_RSS_onepost', 'description' => 'jako na Ekonomicky Denik' );
- $this->WP_Widget('mz_RSS_onepost', 'RSS', $widget_ops);
- }
- function widget( $args, $instance )
- {
- extract($args);
- $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance );
- $content = apply_filters( 'content', empty( $instance['content'] ) ? '' : $instance['content'], $instance );
- ?>
- <div class="box rss">
- <?php if(function_exists('fetch_feed')) {
- include_once(ABSPATH . WPINC . '/feed.php'); // the file to rss feed generator
- $feed = fetch_feed( $content ); // specify the rss feed
- if (!is_wp_error( $feed ) ) {
- $limit = $feed->get_item_quantity(1);
- $items = $feed->get_items(0, $limit); // create an array of items
- $feed->set_timeout(60);
- }else{
- echo $feed->get_error_message();
- }
- }
- ?>
- <?php if($limit) :
- foreach ($items as $item) :
- ?>
- <?php if($title == "justice") : ?>
- <h1><img src="<?php echo plugin_dir_url (__FILE__); ?>rss/justice.png" alt="justice"><span><?php echo $item->get_date('d.m.Y'); ?></span></h1>
- <?php elseif($title == "zdravotnicky") : ?>
- <h1><img src="<?php echo plugin_dir_url (__FILE__); ?>rss/zdravotnicky.png" alt="zdravotnicky"><span><?php echo $item->get_date('d.m.Y'); ?></span></h1>
- <?php elseif($title == "ekonomicky") : ?>
- <h1><img src="<?php echo plugin_dir_url (__FILE__); ?>rss/ekonomicky.png" alt="ekonomicky"><span><?php echo $item->get_date('d.m.Y'); ?></span></h1>
- <?php else : ?>
- <h1><?php echo !empty( $instance['filter'] ) ? wpautop( $title ) : $title; ?></h1>
- <?php endif; ?>
- <?php endforeach; endif; ?>
- <div id="latest">
- <?php
- if ($limit == 0) echo '<div>RSS není momentálně k dispozici.</div>';
- else foreach ($items as $item) : ?>
- <div class="data">
- <a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a>
- </div>
- <?php endforeach; ?>
- </div>
- </div>
- <?php
- }
- function update( $new_instance, $old_instance ) {
- $instance = $old_instance;
- $instance['title'] = $new_instance['title'];
- if ( current_user_can('unfiltered_html') )
- $instance['content'] = $new_instance['content'];
- else
- $instance['content'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['content']) ) );
- $instance['filter'] = isset($new_instance['filter']);
- return $instance;
- }
- function form( $instance )
- {
- $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'content' => '' ) );
- $title = $instance['title'];
- $content = esc_textarea($instance['content']);?>
- <label for="<?php echo $this->get_field_id('title'); ?>">Titulek: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label>
- <p>URL RSS kanálu:</p>
- <input id="<?php echo $this->get_field_id('content'); ?>" name="<?php echo $this->get_field_name('content'); ?>" value="<?php echo $content; ?>" />
- <?php
- }
- }
- add_action( 'widgets_init', create_function('', 'return register_widget("mz_RSS_onepost");') );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement