0

I'm using the default twentythirteen on a wordpress 4.0 site. I have one site in the network right now. I may be adding one or two next year or so. Both blogs are using twentythirteen. Right now the "main" blog only loops out its own posts. I want it to include the child blog. Is there a good way to do this? Doesn't matter if i have to do some manual tinkering in the code when i add a blog to the network since i won't be doing that often.

Edit: i want the posts to appear in the main content area like the posts from the main blog. In the same default style as twentythirteen.

Edit 2: Clarification. The twentythirteen theme have "The Loop" in index.php.

<?php while ( have_posts() ) : the_post(); ?>
    <?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>

If i could get that while loop too fetch the child blogs too i'd get exactly what i'm after. I know this will have more consequenses that needs to be addressed (the paging for example) but this is essentially what i'm after.

  • why not to just say exactly what you want instead of using words like "easy" and "like". I have no idea what you mean by like here.... you want ten posts from each blog to be displayed on the front page of the main blog, therefor 30 post now and 60 in 3 years? I doubt you actually want such an unreadable list. – Mark Kaplun Oct 27 '14 at 2:16
  • I guess the reason i ask the question in an open and vague manner to get diverse answers. But i'll update the question with a more specific so that what i'm after is more understandable. "I doubt you actually want such an unreadable list." Well, there is a pager that makes the list more manageable. – Johan B Oct 27 '14 at 9:33
  • open ended questions are usually being just closed as too broad. This is a Q&A site not a forum. You are supposed to do research and come up with solutions or alternative on which experts can help you figure out why it doesn't work as you expected, help you decide between alternatives, or explain basic facts that will help you understand how some part of the system works. People are very unlikely to design your solutions for you. Maybe the dynamics in SO are different but this is how this site works. – Mark Kaplun Oct 27 '14 at 11:02
0

If you are looking for "easy", then the easiest way is probably to use the RSS widget for that. Get two widgets, one for each blog and you are done. Once you have a third blog just add another widget.

  • I may be missing something but you can only add widgets (at least in twentythirteen) to the sidebars/footer. And each bog would be a separate list. Right? Updating my phrasing in the question. – Johan B Oct 26 '14 at 23:26
  • It is not very hard to create new "sidebars" anywhere you like, IIRC there are even plugins that will let you include a widget as part of yuur content. BUt yeh, the display will luck fetured images if that is what you are trying to display as well – Mark Kaplun Oct 27 '14 at 2:11
  • Sounds like there could potentially be problems with the RSS of the blog too with that solution. – Johan B Oct 27 '14 at 9:34
  • @JohanB, like what problem? – Mark Kaplun Oct 27 '14 at 10:54
0

You can't just loop over all the recent posts in your network install. Each site in a network is made to feel as far as the API and most of user interface goes as a full stand alone wordpress site. It is both a strength and weakness of the system, but it means that doing anything which mixes content from various sites is not trivial.

The key is the function switch_to_blog and restore_current_blog that enable you to use the wordpress API in the context of different blogs

Since you want to have your posts displayed chronologically you first need to create a list of all the recent posts on all site, something like

$blogs_to_fetch = array( the blog ids of the blogs);
$posts = array();

// first we collect data

foreach ($blogs_to_fetch as $blogid) {
  switch_to_blog($blogid);
  $ps = get_posts(parameters to get N latest posts);
  foreach $ps as $p) {
    $posts[] = array('blogid' => $blogid, 'post' => $post);
  }
  restore_current_blog(); // not realy needed, but nicer to the eye
}

$posts = sort_posts($posts); // your own function that sorts the posts by time or by any other creiteria

// now we display

foreach ($posts as $p) {
  switch_to_blog($p['blogid']);
  setup_postdata( $p );
  get_template_part( 'content', get_post_format() );
  restore_current_blog();
}

// cleanup

wp_reset_postdata();

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.