admin管理员组文章数量:1336357
I would like a self-updating list like the one at the bottom left of this page
.html
added to just one page of my website. I don't care how it's done, although I would prefer custom code I can add myself, rather than using a plugin. I have searched on this site for hints, but most results seem to be about listing one's own blog rather than others. Many thanks.
I would like a self-updating list like the one at the bottom left of this page
https://aclerkofoxford.blogspot/p/old-english-wisdom.html
added to just one page of my website. I don't care how it's done, although I would prefer custom code I can add myself, rather than using a plugin. I have searched on this site for hints, but most results seem to be about listing one's own blog rather than others. Many thanks.
Share Improve this question asked Jul 15, 2020 at 7:46 legatrixlegatrix 1032 bronze badges 2- Did you try the RSS/Feed widget? – fuxia ♦ Commented Jul 15, 2020 at 8:09
- Or do you mean posts from a network, from a Multisite installation? – bueltge Commented Jul 15, 2020 at 8:59
1 Answer
Reset to default 1There's a function called fetch_feed, and an example of code to write custom code to do this for a single site contributed in the comments on that page. If you're comfortable writing a bit more custom code, it would be easy to alter this to pull from several feeds, and limit them to e.g. 1 or 2 latest posts from each site.
Note This approach is fine for a low traffic site, but for a busy site you will be hitting these RSS feeds on every pageload to your site, so you may want to think about implementing caching.
Here's the code to fetch and render a single RSS feed, you should be able to work from this. Refer to the fetch_feed documentation and this pages with more descrtiption of the fields in RSS for more detail
<?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/rss/feed/goes/here' );
$maxitems = 0;
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 ) : ?>
<li><?php _e( 'No items', 'wpdocs_textdomain' ); ?></li>
<?php else : ?>
<?php // Loop through each feed item and display each item as a hyperlink. ?>
<?php foreach ( $rss_items as $item ) : ?>
<li>
<a href="<?php echo esc_url( $item->get_permalink() ); ?>"
title="<?php printf( __( 'Posted %s', 'wpdocs_textdomain' ), $item->get_date('j F Y | g:i a') ); ?>">
<?php echo esc_html( $item->get_title() ); ?>
</a>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
本文标签:
版权声明:本文标题:blogroll - How to add list of other blogs, with latest posts from those blogs, to a single page of my website? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742261160a2442538.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论