开发者 | jp2112 |
---|---|
更新时间 | 2014年8月16日 21:14 |
捐献地址: | 去捐款 |
PHP版本: | 3.5 及以上 |
WordPress版本: | 3.9 |
版权: | GPLv2 or later |
版权网址: | 版权信息 |
fetch_feed
, which was introduced in WordPress 2.8. Works and tested in WordPress 3.5 and above. By default, feeds are cached for 12 hours. You can choose a shorter (or longer) cache time.
Feed items are wrapped in a div tag, with class "jpgetrssfeed" so you can style the output in your CSS file. The items list is surrounded by <ul></ul>
tags, with each feed item listed in a <li></li>
tag. However, you can specify a new CSS class to style output differently for different feeds.
You can output the feed item description along with each feed item link.
A button is added to the post editor toolbar so you can insert the shortcode in your posts or pages.
With help from:
http://codex.wordpress.org/Function_Reference/fetch_feed
Shortcode
To display a feed on any post or page, use this shortcode:
[jp-rss-feed]
Make sure you go to the plugin settings page after installing to set options.
If you use and enjoy this plugin, please rate it and click the "Works" button below so others know that it works with the latest version of WordPress.
You can use the plugin in two ways:
if (function_exists('jp_get_rss_feed_items')) { jp_get_rss_feed_items(array( 'url' => "http://somefeed.com/rss", 'numitems' => 5, 'nofollow' => true, 'cssclass' => 'myclass', 'getdesc' => false, 'opennewwindow' => false, 'show' => true )); }
This will:
function_exists
check so that your site doesn't go down if the plugin is inactive.
[jp-rss-feed numitems="3"]
This will take the settings from the Settings page (or the defaults if a setting is missing) and apply them to the shortcode, except there will only be three items even if you specified 5 on the Settings page. In this way you can override settings by passing them to the shortcode at runtime.
The plugin arguments and default values may change over time. To get the latest list of arguments and defaults, look at the settings page after installing the plugin.
Add this line of code to your functions.php:
add_filter('widget_text', 'do_shortcode');
Or, install a plugin to do it for you: http://blogs.wcnickerson.ca/wordpress/plugins/widgetshortcodes/
Now, add the built-in text widget that comes with WordPress, and insert the JP's Get RSS Feed shortcode into the text widget. See above for how to use the shortcode.
See http://digwp.com/2010/03/shortcodes-in-widgets/ for a detailed example.
Keep in mind, if you want to show your blog feed in a sidebar widget, WordPress already has a built-in "Recent Posts" widget for that.
Add this to your functions.php:
remove_action('admin_enqueue_scripts', 'jpgrf_ed_buttons');
Clear your browser cache and also clear your cache plugin (if any). If you still don't see anything, check your webpage source for the following:
<!-- JP's Get RSS Feed: plugin is disabled. Check Settings page. -->
This means you didn't pass a necessary setting to the plugin, so it disabled itself. You need to pass at least the URL, either by entering it on the settings page or passing it to the plugin in the shortcode or PHP function. You should also check that the "enabled" checkbox on the plugin settings page is checked. If that box is not checked, the plugin will do nothing even if you pass it a URL.
If the RSS feed only includes 10 items at a time, you will only ever be able to request 10 items at most. (Hint: Load the feed in your browser to confirm) Even if you request 100 items, you will only get at most 10. You should contact whomever controls the feed and ask them to increase the number of items in their feed. For WordPress blogs, go to Settings » Reading and change the value of "Syndication feeds show the most recent ___ items" to change the number of feed items available.
If you are using the Genesis framework from Studiopress, you might use the plugin like this:
add_action('genesis_after_post_content', 'showrss'); function showrss() { if (is_page('faq')) { // we are on the FAQ page... if (function_exists('jp_get_rss_feed_items')) { // and the function exists... echo '<h3>Latest Articles From my Favorite RSS Feed</h3>'; jp_get_rss_feed_items(array('url' => "http://feeds.feedburner.com/MyFavoriteRSSFeed", 'show' => true)); // or: echo jp_get_rss_feed_items(array('url' => "http://feeds.feedburner.com/MyFavoriteRSSFeed")); } } }
This code would go in your functions.php file, or (ideally) in a plugin. Check the Hook Reference to determine where you want to place the output. The above example (remember, for Genesis framework only) would show the last five articles from a given RSS feed at the bottom of the 'FAQ' page.
Use an array and a foreach loop:
if (function_exists('jp_get_rss_feed_items')) { // create array $feedslist = array( "My feed URL number one", "My feed URL number two", "My feed URL number three" ); // loop through array and call plugin foreach ($feedslist as $item) { jp_get_rss_feed_items(array('url' => $item, 'show' => true)); } }
This will list the last five items from each feed in its own unordered list.
But suppose you want a different CSS class for each one. Use a for loop instead.
if (function_exists('jp_get_rss_feed_items')) { // create array $feedslist = array( "My feed URL number one", "My feed URL number two", "My feed URL number three" ); // loop through array and call plugin for ($i = 0, $size = count($feedslist); $i < $size; $i++) { jp_get_rss_feed_items(array('url' => $feedslist[$i], 'cssclass' => 'jpgetrssfeed_' . $i , 'show' => true)); } }
So your CSS classes would be
Use array_rand
:
if (function_exists('jp_get_rss_feed_items')) { // create array $feedslist = array( "My feed URL number one", "My feed URL number two", "My feed URL number three" ); // get random index from array $item = array_rand($feedslist, 1); // pass randomly selected array member to plugin jp_get_rss_feed_items(array('url' => $feedslist[$item], 'show' => true)); }
This selects one URL randomly and passes it to the plugin.
Feed items are wrapped in a div tag, with class "jpgetrssfeed" (or whatever you change it to) so you can style the output in your CSS file. The items list is surrounded by <ul></ul>
tags, with each feed item listed in a <li></li>
tag.
So you could add something like this in your style.css:
.jpgetrssfeed {border:1px solid gray;margin:10px 0} .jpgetrssfeed ul li {list-style-type:circle}
You can also specify your own class, or use a different class name for each shortcode to style it differently. Ex:
In my style.css file I add the following
.rssorange {border:1px solid #FF9900;margin:10px 0}
.rssblue {border:1px solid blue;margin:10px 0}
.rssred {border:1px solid red;margin:10px 0}
I specify each class in my shortcodes as follows:
[jp-rss-feed url="http://somefeed.com/rss" cssclass="rssorange"]
[jp-rss-feed url="http://some_other_feed.com/rss" cssclass="rssblue"]
[jp-rss-feed url="http://some_new_feed.com/rss" cssclass="rssred"]
Each feed will be surrounded by a different color border.
See the examples above. Before you call the shortcode or the PHP function, echo your header like this:
echo '<h3>Latest Articles From my Favorite RSS Feed</h3>';
Then call the PHP function or shortcode.
Add this to your functions.php:
remove_action('admin_head', 'insert_jpgrf_admin_css');
This plugin adds one or more toolbar buttons to the HTML editor. You will not see them on the Visual editor. The label on the toolbar button is "RSS Feed".
Enter a lower character limit on the plugin's options page.
Check the number of characters in the feed item description textbox. Try increasing it. Remember that the character limit cuts off the item description. If the item description contains HTML and you cut it off in the middle, you are leaving unclosed HTML tags which can affect the rest of the page.
See the plugin settings page. There is a dropdown box for you to indicate the sort order. The default is newest first, change the dropdown box to 'oldesfirst' and the items will be sorted in reverse date order.
On the plugin settings page, go to the "Parameters" tab. There is a list of possible parameters there along with the default values. Make sure you are spelling the parameters correctly. The Parameters tab also contains sample shortcode and PHP code.