是否可以从多个wordpress安装(没有多站点)中获取最新帖子以显示在单个主页上


Is it possible to fetch latest posts from multiple wordpress installations (without multisite) to display on a single homepage?

我在不同的子域上安装了多个wordpress,我需要在主页上列出每个安装的最新帖子。我需要一个单一的安装(多站点),还是可以从多个安装?

您可以通过RSS提要从不同网站获取最新帖子。这个任务有插件,或者你可以自己编写代码。如果你想自己编码,请参阅以下内容:

用法:

<?php $feed = fetch_feed( $uri ); ?>

此示例将检索并显示现有RSS提要的链接列表,将选择限制为五个最新项目:

<h2><?php _e( 'Recent news from Some-Other Blog:', 'my-text-domain' ); ?></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 ) : ?>
        <li><?php _e( 'No items', 'my-text-domain' ); ?></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', 'my-text-domain' ), $item->get_date('j F Y | g:i a') ); ?>">
                    <?php echo esc_html( $item->get_title() ); ?>
                </a>
            </li>
        <?php endforeach; ?>
    <?php endif; ?>
</ul>

来源:Wordpress Feeds,Wordpress Fetch Feed。