WordPress.org

Ready to get started?Download WordPress

Forums

List latest post from all my subscriber-level blogs (2 posts)

  1. osby
    Member
    Posted 1 year ago #

    Hi!

    I am trying to create a page where I can see all the latest posts from the blogs where I have a subscriber-level.

    I've been fiddeling with get_blogs_of_user and it leaves me a neat list of all my blogs. However I would prefer if I could just see the ones where I am only a Subscriber.

    So I can find the blogs. Now I want to build a list where all the latest posts appear from those blogs.

    Any ideas?

    Here is some of my code.

    <?php global $current_user;
    	  $blogs = get_blogs_of_user( $current_user->ID );
    	     if($blogs) {
    	     	 foreach ( $blogs as $blog ) {
    	         echo '<li><a href="http://' . $blog->domain . $blog->path .'">' .  $blog->userblog_id . '</a></li>';
    	         global $switched;
    	             switch_to_blog($blog->userblog_id);
    	             echo 'You switched from blog ' . $switched . ' to ' . $blog->userblog_id;
    	             restore_current_blog();
    	             echo 'You switched back.';
    			}
    	     }
    	?>
    
    	<?php query_posts( 'blogid=4' );
    		while ( have_posts() ) : the_post(); ?>
    	<?php the_title(); ?>
    	<?php endwhile; ?>
  2. David Sader
    Member
    Posted 1 year ago #

    Here's an idea, but it generates a pile of queries on the db with more subscriber blogs:

    <ul>
    	<?php
    		$user = get_current_user_id();
    		$blogs = get_blogs_of_user( $user );
    	     if( $blogs ) {
    	     foreach( $blogs as $blog ) {
    		switch_to_blog( $blog->userblog_id );
     			$query = new WP_Query( 'posts_per_page=1' );
     			 	if ($query->have_posts()) :
      					while ($query->have_posts()) : $query->the_post();
    					?>
    					<li>
    					<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    					</li>
    					<?php
    					endwhile;
    				endif;
    		restore_current_blog();
    				}
    	     }
    	?>
    </ul>

    to see more than one post per blog, change posts_per_page=1

Topic Closed

This topic has been closed to new replies.

About this Topic