最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

blogroll - How to add list of other blogs, with latest posts from those blogs, to a single page of my website?

programmeradmin3浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 1

There'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>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论