0

I need to list all current WordPress Multisite Blogs apart from the one the user is on and the main blog. We have a 404 page where we'd like to recommend other blogs (physical places) apart from the blog the user is current on and the main blog.

Here is our structure:

Main Blog (places) Blog 1 (New York) Blog 2 (London) Blog 3 (Paris)

I can list all blogs but need to remove the main blog and the one the user is cirrently on from the list.

<?php

$bcount = get_blog_count();

global $wpdb;
$blogs = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE 
spam = '0' AND deleted = '0' and archived = '0' and public='1'"));
if(!empty($blogs)){
?><ul class="menu"><?php
foreach($blogs as $blog){
    $details = get_blog_details($blog->blog_id);
    if($details != false){
        $addr = $details->siteurl;
        $name = $details->blogname;
        if(!(($blog->blog_id == 1)&&($show_main != 1))){
            ?>
            <li class="menu-item<?php if($counter == get_current_blog_id()){ echo ' current-menu-item';}?>">
                <a href="<?php echo $addr; ?>"><?php echo $name;?></a>
            </li>
            <?php
        }
    }
}
?></ul><?php
} ?>

Thanks

0

This will list all blogs except the current one and the main one:

$blogs = get_sites(
    array(
    'number' => 99999999,
    'site__not_in' => array( get_current_blog_id(), 1 )
    )
);

foreach( $blogs as $blog ) {
    $addr = $blog->siteurl;
    $name = $blog->blogname;
    echo $addr . " - " . $name . "<br>";
}

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.