I would like a self-updating list like the one at the bottom left of this page


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.

  • Did you try the RSS/Feed widget? – fuxia Jul 15 at 8:09
  • Or do you mean posts from a network, from a Multisite installation? – bueltge Jul 15 at 8:59

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.com/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 );
    <?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 ) : ?>
                <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() ); ?>
        <?php endforeach; ?>
    <?php endif; ?>
| improve this answer | |
  • This worked perfectly! Thanks very much. – legatrix Jul 15 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.