Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //This file is needed to be able to use feed parsing functions.
- include_once( ABSPATH . WPINC . '/feed.php' );
- // parse any RSS feed
- function custom_fetch_feed( $args = '' ) {
- // default arguments (additional ones can be added at will)
- $defaults = array(
- 'url' => '', // feed url
- 'num' => 7, // max items to display
- );
- // Parse incomming $args into an array and merge it with $defaults
- $args = wp_parse_args( $args, $defaults );
- // OPTIONAL: Declare each item in $args as its own variable i.e. $type, $before.
- extract( $args, EXTR_SKIP );
- // Get a SimplePie feed object from the specified feed source.
- $feed = fetch_feed( $url );
- // Checks that the object is created correctly
- if ( !is_wp_error( $feed ) ) {
- // Figure out how many total items there are, but limit it to parameter.
- $maxitems = $feed->get_item_quantity( $num );
- // Build an array of all the items, starting with element 0 ( first element ).
- $feed_items = $feed->get_items( 0, $maxitems );
- }
- // if there are no item in the feed
- if ( $maxitems == 0 ) {
- $content = '<!-- No items -->';
- } else {
- $content = '';
- // Loop through each feed item and display each item as a hyperlink.
- foreach ( $feed_items as $item ) :
- $content .= '<!-- do whatever with feed object -->';
- endforeach;
- }
- return $content;
- }
Advertisement
Add Comment
Please, Sign In to add comment