Make a list of sites for each user in WPMU – switch_to_blog (display in SITE_ID: 1)

0 Votes
    762 Views

site list - multisites list in site id 1

page.php (site_id= 1)

<?php // view all sites for all users in site network ID 1

     $blogs = get_blog_list(  '0',  'all' ); // ALL BLOGS
        if ( 0 < count( $blogs ) ) :
        foreach( $blogs as $blog ) : 
        switch_to_blog( $blog[ 'blog_id' ] ); ?>



    <tr class="row230<? echo  $blog->blog_id; ?>">

    <td><a href="<? echo get_home_url(); ?>"><?php echo get_bloginfo('name'); ?></a></td>
    <td><? echo get_home_url(); ?></td>
    <td><?php if(get_field('pubblic-site', 'option') == 'yes'){?> Yes<? } else { ?> NO <? }; ?></td>
    <td><?php $count = 0; $pages = get_pages(); foreach($pages as $page) {$count++;} echo $count;?></td>

    </tr>  

    <?php 
    restore_current_blog(); /*end switch blog*/
    endforeach; /*end blogs for blog*/
    endif; /*end if blogs */ 
    ?>

I have seen several methods to make a list of blogs, but I would like to get more out of the code that is currently widespread in wordpress.
It is to get more data from each blog, but now grabs just the basic information such as name of the blog, url, id blog, patch … (blog_details).

Well, imagine that we need a complete list with the following information:

plugin assets, number of pages, number of items, name template, categories and more data …. we need …
This code is wonderful to get any data from every blog or site, and make a list, but my problem is: each user who logs on can see all the sites in general (entire network). The following code does not work for me but it would be great to be working with $current_user

page.php (site_id= 1)

<?php /*THIS CODE NOT FUNCTION FOR BLOG LIST*/
if(is_user_logged_in()) {
global $current_user;


  $blogs = get_blogs_of_user( $current_user->id );

if ( 0 < count( $blogs ) ) :
    foreach( $blogs as $blog ) : 
  switch_to_blog( $blog );
?>

<li> <a href="<? echo get_home_url(); ?>"><?php echo get_bloginfo('name'); ?></a>
<br />
Url: <? echo get_home_url(); ?><br >
Public: <?php if(get_field('pubblic-site', 'option') == 'yes'){?> Yes<? } else { ?> NO <? }; ?><br />
Pages create: <?php $count = 0; $pages = get_pages(); foreach($pages as $page) {$count++;} echo $count;?>
</li>



<?  

restore_current_blog();
endforeach;
endif;

 } ?>

3

Answers


Please signup or login to answer this question.