我有一个关于RSS提要的问题。我正在使用wordpress 3.2.1和其他网站rss提要在我的网站。我的要求是获取的提要月明智,并显示在我的网站侧栏。
目前,我正在使用rss小部件,并在侧栏中显示提要,但它们的格式如下:
我将非常感谢你的帮助。提前谢谢。
更新:2012年3月13日
此代码存在于index.php中。
<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');
$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>发布于 2012-03-09 16:09:22
你可以手动完成。只需使用wordpress本机函数馈送即可。
你甚至有一个例子:
<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>您只需将其放在sidebar.php中,只要显示提要即可。
编辑行:
$rss = fetch_feed('http://example.com/rss/feed/goes/here');...and将url指向正确的提要。和:
$maxitems = $rss->get_item_quantity(5); ...to指定要显示多少项(示例中有五项)
然后检查UL中的foreach,您可以在那里显示提要的样式。
默认情况下,fetch_feed函数将缓存提要12个小时。如果你需要每隔30天做一次,你可以使用wordpress的瞬态API来完成它,而不需要麻烦。
https://stackoverflow.com/questions/7585871
复制相似问题