How to fetch rss feed month wise from other website
I have a question regarding RSS feeds. I am using wordpress ver 3.2.1 and using other website rss feeds in my website. My requirement is to fetch the feeds month wise and to show in my website side bar.
Currently i am using rss widget and showing the feeds in sidebar but they are coming in below format:
- Thu 9-29 4:30pm Elementary Quest - Parent Information Night
- Thu 10-6 -All Day- Half-Day: Elementary Conferences
I will be very thankful for your help. Thanks in advance.
Update: Mar 13 2012
This code is present in index.php
<h2><?php _e('Recent news from Some-Other Blog:'); ?>&开发者_如何学Golt;/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');
$rss = fetch_feed('http://lakewashington.intand.com/index.php?type=export&action=rss&schools=48&groups=884,876,874,996');
print_r($rss);
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 esc_url( $item->get_permalink() ); ?>'
title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
<?php echo esc_html( $item->get_title() ); ?></a>
</li>
<?php endforeach; ?>
</ul>
You can do it manually. Just use wordpress native function fetch_feed.
You even have an example in there:
<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 esc_url( $item->get_permalink() ); ?>'
title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
<?php echo esc_html( $item->get_title() ); ?></a>
</li>
<?php endforeach; ?>
</ul>
You just need to put that in your sidebar.php, wherever you need to show the feed.
Edit the line:
$rss = fetch_feed('http://example.com/rss/feed/goes/here');
...and point the url to the correct feed. And:
$maxitems = $rss->get_item_quantity(5);
...to specify how many items to show (five in the example)
Then check the foreach inside the UL, there you can style how the feed are shown.
By default, fetch_feed function will cache the feeds for 12 hours. If you need to do it every 30 days, you can use the wordpress's Transients API to accomplish that without hassle.
精彩评论