Created
January 25, 2014 09:20
-
-
Save maimai-swap/8613868 to your computer and use it in GitHub Desktop.
Wordpress / show Another RSS feed / from http://mypacecreator.net/blog/archives/2021
This file contains hidden or 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 | |
| // from http://mypacecreator.net/blog/archives/2021 | |
| //以下3行の項目を任意に変更 | |
| $display_posts_count = 10; //実際に表示したい記事件数 | |
| $get_posts_count = 20; //取得する記事件数(PR記事を含むので$display_posts_countより少し多めに設定) | |
| $feed = fetch_feed('http://rssblog.ameba.jp/conboy/rss20.xml'); //取得したいRSS | |
| //以下は必要なければ変更しなくてOK | |
| $counter = 0; //ループ回数カウンター | |
| include_once(ABSPATH . WPINC . '/feed.php'); | |
| if (!is_wp_error( $feed ) ) : //エラーがなければ | |
| $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