Skip to content

Instantly share code, notes, and snippets.

@mavieth
Created January 12, 2016 18:18
Show Gist options
  • Select an option

  • Save mavieth/aa422aa6efa62825a694 to your computer and use it in GitHub Desktop.

Select an option

Save mavieth/aa422aa6efa62825a694 to your computer and use it in GitHub Desktop.
function rss_blog(){ ?>
<h2><?php _e( 'PTRC via Yahoo Finanace:', 'my-text-domain' ); ?></h2>
<?php // Get RSS Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( 'http://feeds.finance.yahoo.com/rss/2.0/headline?s=PTRC&region=US&lang=en-US' );
if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 5.
$maxitems = $rss->get_item_quantity( 6 );
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items( 0, $maxitems );
endif;
?>
<ul class="yahoo-rss">
<?php if ( $maxitems == 0 ) : ?>
<li><?php _e( 'No items', 'responsive' ); ?></li>
<?php else : ?>
<?php // Loop through each feed item and display each item as a hyperlink. ?>
<?php foreach ( $rss_items as $item ) : ?>
<li>
<a href="<?php echo esc_url( $item->get_permalink() ); ?>"
title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('j F Y | g:i a') ); ?>">
<?php echo esc_html( $item->get_title() ); ?>
</a>
<br>
<strong><?php echo esc_html( $item->get_date() ); ?></strong>
<p><?php echo esc_html( $item->get_content() ); ?></p>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
<button></button>
<?php
}
add_shortcode( 'rss', 'rss_blog' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment