他サイトのRSSを表示する

他サイトのRSSをサイドバーなどに表示する
http://wpzine.com/importing-feeds-using-wordpress/

例1)

<h2>Smashing Network</h2>
<div class="sm">
<?php include_once(ABSPATH.WPINC.'/rss.php');
wp_rss('http://rss1.smashingmagazine.com/feed/?f=smashing-network', 5); ?>
</div>

例2)

<?php include_once(ABSPATH.WPINC.'/rss.php');
wp_rss('http://rss1.smashingmagazine.com/feed/?f=smashing-network', NUMBER); ?>

wp_rssは非推奨らしい。
http://codex.wordpress.org/Function_Reference/wp_rss

かわりに「fetch_feed」を使うようになるらしい。
http://codex.wordpress.org/Function_Reference/fetch_feed

<h2><?php _e('Recent news from Some-Other Blog:'); ?></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://example.com/rss/feed/goes/here');
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(5); 

    // Build an array of all the items, starting with element 0 (first element).
    $rss_items = $rss->get_items(0, $maxitems); 
endif;
?>

<ul>
    <?php if ($maxitems == 0) echo '<li>No items.</li>';
    else
    // 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 '.$item->get_date('j F Y | g:i a'); ?>'>
        <?php echo $item->get_title(); ?></a>
    </li>
    <?php endforeach; ?>
</ul>

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)