Support » Networking WordPress » List multisites blog posts on main site blog page

Viewing 2 replies - 1 through 2 (of 2 total)
  • How do I list all WordPress multisite posts on a main site’s blog page?

    Something like this on your front page template will work. The idea is that you have a loop to fetch all blogs, and inside that loop there is another loop that gets the posts from each blog. I wouldn’t try this on a large network!

    <?php
      // get all blogs
      $blogs = get_sites();
      if ( 0 < count( $blogs ) ) :
    ?>
    <h3>Microsites hosted on this network:</h3>
    <?php foreach( $blogs as $blog) :
    if (1 == $blog->blog_id) continue;
    switch_to_blog( $blog->blog_id );
    
    $description  = get_bloginfo( 'description' );
    $blog_details = get_blog_details( $blog->blog_id );
    $posts = get_posts(); ?>
    
    <div class="blog">
      <h3>
        <a href="<?= $blog_details->path ?>"><?= $blog_details->blogname ?></a>
      </h3>
      <?= $description ?>
      <ul>
      <?php foreach ($posts as $post) : ?>
      <li><?= $post->post_title ?></li>
      <?php endforeach; ?>
      </ul>
    </div>
    
    <?php endforeach; ?>
    <?php endif;
    switch_to_blog(1); ?>
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List multisites blog posts on main site blog page’ is closed to new replies.