The link provided by Christine Cooper has a great answer. There are many ways, and you can look through the plugin WP Latest Posts for code, too.
Start by looking at the get_last_updated function. WordPress provides get_posts as the basis to retrieve posts, even across a network. In addition, take a look at switch_to_blog() to pull from the across the network. The final piece to the puzzle is the setup_postdata for global post data.
This piece of code may be helpful. I apologize, the source is unknown but is not originally mine.
$blogs = get_last_updated();
foreach( $blogs AS $blog ) {
switch_to_blog( $blog["blog_id"] );
$lastposts = get_posts( 'numberposts = 1' );
foreach( $lastposts as $post ) :
setup_postdata( $post );
?>
<a href="https://wordpress.stackexchange.com/questions/225339/<?php the_permalink(); ?>" style="color:white !important;"><?php the_author(); ?></a>
- <a href="https://wordpress.stackexchange.com/questions/225339/<?php the_permalink(); ?>" style="color:white !important; margin-bottom: 5px;"><?php the_title(); ?></a></li></ul> <br />
<?php
endforeach;
restore_current_blog();
}
The array in get_posts
can help select the conditions for the posts. For example, you may want to look at offset because it must be present for the posts_per_page
( interchangeable with numberposts
) to work. Read over the other conditions, too, such as needing global post
.