アメブロRSSから[PR]を外してfetch_feedするやーつ
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 | |
//以下3行の項目を任意に変更 | |
$display_posts_count = 5; //実際に表示したい記事件数 | |
$get_posts_count = 10; //取得する記事件数(PR記事を含むので$display_posts_countより少し多めに設定) | |
$feed = fetch_feed('http://feedblog.ameba.jp/rss/ameblo/**blogname**/rss20.xml'); //取得したいRSS | |
// | |
$counter = 0; //ループ回数カウンター | |
include_once(ABSPATH . WPINC . '/feed.php'); | |
if (!is_wp_error( $feed ) ) : //エラーがなければ | |
date_default_timezone_set('Asia/Tokyo'); //タイムゾーンを日本時間に設定 | |
$maxitems = $feed->get_item_quantity($get_posts_count); //取得件数 | |
$feed_items = $feed->get_items(0, $maxitems); //指定件数分の配列作成 | |
endif; | |
?> | |
<ul> | |
<?php | |
if ( $feed_items == 0 ) echo '<li>新しい記事はないようです</li>'; | |
else foreach ( $feed_items as $item ) : | |
if( !preg_match('/^PR:/', $item->get_title() ) && $counter < $display_posts_count ): //PR記事の除外 && 表示件数が設定件数を超えないかチェック | |
?> | |
<li><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a><br /> | |
<?php echo $item->get_date('Y.m.d'); ?>更新</li> | |
<?php $counter++; | |
endif; | |
endforeach; ?> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment