Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- ********************************************************************************
- * *
- * WordPress: Shortcode for display Feed RSS *
- * Author: Lucas S. B. Mastella <lucas[at]bello[dot]li> *
- * Site: http://bello.li/ *
- * Date: 03/03/2012 *
- * *
- ********************************************************************************
- * *
- * Attribute: URL, NUM, TARGET *
- * Default: NUM=3, TARGET="blank" *
- * num = [0-9]^ *
- * target = [blank, self, parent, top] *
- * *
- * Ex.: [feed url="http://bello.li/feed/" num=5 target="self"] *
- * *
- ********************************************************************************
- * *
- * This program is free software: you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation, either version 3 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful. *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program. If not, see <http://www.gnu.org/licenses/>. *
- * *
- ********************************************************************************
- *
- * Thank's to:
- * RSS Widget doesn’t update: http://newtotheweb.net/2009/10/25/rss-widget-doesnt-update/
- *
- */
- function feed_fetcher( $atts ) {
- // Update Cache
- add_filter( 'wp_feed_cache_transient_lifetime', create_function( '$a', 'return 0;' ) );
- // Shortcode Attribute
- extract( shortcode_atts( array(
- 'url' => '',
- 'num' => '3',
- 'target' => 'blank'
- ), $atts ) );
- // Fetch Feed
- include_once( ABSPATH . WPINC . '/feed.php' );
- $rss = fetch_feed( $url );
- $max = $rss->get_item_quantity( $num );
- $rss_itens = $rss->get_items( 0, $max );
- if ( $max == 0 ) echo 'No URL has been added!';
- else
- foreach ( $rss_itens as $item ) :
- echo '<a href="' . $item->get_permalink() . '" target="_' . $target . '">' . $item->get_title() . '</a><br />';
- endforeach;
- }
- add_shortcode( 'feed', 'feed_fetcher' );
- ?>
Add Comment
Please, Sign In to add comment