Last active
December 17, 2015 20:29
-
-
Save senlin/5667814 to your computer and use it in GitHub Desktop.
Get last 5 episodes to show if "rss" custom field has been filled in. If not, output other message. See Google+ https://plus.google.com/u/0/116025569345227867532/posts/GcWYWECU7pd
This file contains 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 // Google+ post https://plus.google.com/u/0/116025569345227867532/posts/GcWYWECU7pd | |
include_once(ABSPATH.WPINC.'/feed.php'); | |
{ | |
$grss=get_post_meta($post->ID, 'rss', true); | |
$rss = fetch_feed($grss); | |
if (!is_wp_error($rss)) { // Checks that the object is created correctly | |
$maxitems = $rss->get_item_quantity(5); | |
$rss_items = $rss->get_items(0, $maxitems); | |
} | |
if (!empty($maxitems)) { | |
?> | |
<ol> | |
<b><?php _e( 'Last Five Episodes', 'textdomain' ); ?></b> | |
<?php | |
// Loop through each feed item and display each item as a hyperlink. | |
foreach ( $rss_items as $item ) : ?> | |
<li> | |
<a href="<?php echo $item->get_permalink(); ?>' title='<?php echo __( 'Posted ', 'textdomain' ) . $item->get_date( 'j F Y | g:i a' ); ?>"> | |
<?php echo $item->get_title(); ?> | |
</a> | |
</li> | |
<?php endforeach; ?> | |
</ol> | |
<?php } else { ?> | |
<ul><li><?php _e( 'No RSS Feed', 'textdomain' ); ?></li></ul> | |
<?php } | |
} ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment