• Resolved sebastien83

    (@sebastien83)


    Hi,
    I use WordPress 4 multisite with Pinboard theme. I want show items from other blogs order by date in my main blog .
    I managed to publish articles from other blogs on my main blog, but I can not order them by date.
    My code :

    <?php
    /*
    Template Name: Blogs, Left Sidebar
    */
    ?><?php get_header(); ?>
    	<?php global $pinboard_page_template; ?>
    	<?php $pinboard_page_template = 'template-blog-left-sidebar-blogs.php'; ?>
    	<?php if( pinboard_get_option( 'location' ) ) : ?>
    		<?php pinboard_current_location(); ?>
    	<?php endif; ?>
    	<div id="container">
    		<section id="content" class="column twothirdcol">
    			<?php $args = array(
    'orderby' => 'date',
    'order' => 'DESC',
    'posts_per_page' => '1',
    'paged' => max( 1, get_query_var( 'paged' ) )
    ); ?>
    			<?php if( pinboard_get_option( 'blog_exclude_portfolio' ) ) : ?>
    				<?php $args['cat'] = '-' . pinboard_get_option( 'portfolio_cat' ); ?>
    			<?php endif; ?>
                <?php $original_blog_id = get_current_blog_id(); ?>
                <?php $bids = array(20,21,22,23,24,27,8,28,29,25,30,26,14,31,33,34,38,41,42,43);
    			foreach($bids as $bid):
    			switch_to_blog($bid); //switched to blog with blog_id $bid
    ?>
    
                 <?php $wp_query = new WP_Query( $args ); ?>
    <?php if( $wp_query->have_posts() ) : ?>
    				<div class="entries">
    					<?php while( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
    						<?php get_template_part( 'content_blogs', get_post_format() ); ?>
    
    					<?php endwhile; ?>
    				</div><!-- .entries -->
    			<?php else : ?>
    				<?php pinboard_404(); ?>
    			<?php endif; ?>
    
    			<?php wp_reset_postdata(); ?>
    			<?php $wp_query = $wp_the_query; ?>
                <?php
    			 endforeach ;
    			switch_to_blog( $original_blog_id ); ?>
    		</section><!-- #content -->
    		<?php get_sidebar(); ?>
    		<div class="clear"></div>
    	</div><!-- #container -->
    <?php get_footer(); ?>

    If anyone can help me it would be nice!
    Tanks,
    Seb
    (Sorry for my english)

Viewing 2 replies - 1 through 2 (of 2 total)
  • Egads, that is a lot of switch_to_blog switches!

    I offer a different approach:

    Have a read of how Donncha’s Sitewide Tags plugin could do the post aggregate work for you. Once all posts are duped to your main blog, there may be no need to fiddle with your theme template as the usual post loops will work as expected.

    I use this plugin do what it looks like you are trying to do – except I do not need to modify any code in a theme. I just install the plugin, initialize it, and all posts from every blog in the network appear on the main(aka Tags) blog – in order they were all published.

    If you still want network posts to be looped separately from your main blog posts, create a separate tags blog to aggregate, then you only need one “switch_to_blog” loop on your main sidebar.

    Thread Starter sebastien83

    (@sebastien83)

    Hi,
    Thanks for your reply, I would have preferred not to use plugin but I’ll try your solution.

    Thanks,
    Seb

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Multisite and items in main blog from other blogs’ is closed to new replies.