0

I would like to know

How to hide blogs by id in multisite blog list? Here is my code sample, it list 3 newest blog post with 3 difference blogs

    <?php 
     $blogs = get_last_updated(' ', 0, 3); 

     foreach ($blogs AS $blog) {;
     switch_to_blog($blog["blog_id"]);

     $lastposts = get_posts('numberposts=1&orderby=date');
     foreach($lastposts as $post) : setup_postdata($post);
    ?>

<div class="col-sm-4 blog-newest">

    <!-- blog name -->
    <h3><?php echo $blog_title = get_bloginfo( 'name' ); ?></h3>

    <!-- Link to blog -->
    <a href="<?php echo get_page_link($post->ID); ?>"> 
        <?php echo $post->post_title; ?>
    </a>

</div>

<?php               
    endforeach;
    restore_current_blog();
    }
 ?> 

Thanks for answers

1 Answer 1

0

How about an if statement?

<?php 
    $blogs = get_last_updated(' ', 0, 3); 

    foreach ($blogs AS $blog) {;
    switch_to_blog($blog["blog_id"]);

    $lastposts = get_posts('numberposts=1&orderby=date');
    foreach($lastposts as $post) : setup_postdata($post);
?>

<?php if $blog["blog_id"] != 1 { ?> // Run the Output if the ID is not X

    <div class="col-sm-4 blog-newest">

    <!-- blog name -->
    <h3><?php echo $blog_title = get_bloginfo( 'name' ); ?></h3>

    <!-- Link to blog -->
    <a href="<?php echo get_page_link($post->ID); ?>"> 
        <?php echo $post->post_title; ?>
    </a>

    </div>

    <?php               
        endforeach;
        restore_current_blog();
    }
    ?> 

<?php } ?>
2
  • Thanks for the answer, basically thing is, if the blog id is 1, 2, 3. The system skip it and take next id which is next "not skipped id" and show it
    – MSI
    Commented Jan 5, 2017 at 13:09
  • That would be the result of the code that I provided. Where if $blog["blog_id"] != 1 would result in outputting data for all blogs that are not blog ID of 1. You could exempt more blogs by adding additional statements to the if. Commented Jan 6, 2017 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.