WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How can I call the BlogID? (3 posts)

  1. hauruapai
    Member
    Posted 4 years ago #

    Hi,

    I am adding in a page that will list all of my subdomains but I want to filter out the name of the subdomain that the page is called from ie:

    I have
    mydomain.com
    1.mydomain.com
    2.mydomain.com
    3.mydomain.com

    If a person on mydomain.com goes to view the list of other subdomains I don't want mydomain.com to come up in the list etc

    I have had a look at some plugins but the closest one that I can find to do want I want does not remove the current site from the list, so I will do my own. I have had a play with different terms but have not got the right one yet!

    thank you for your time :D

  2. David Sader
    Member
    Posted 4 years ago #

    $blog_id is a global. At least two (now deprecated in WP3 RC3) WPMU functions can produce a list of blogs, get_last_updated, or get_blog_list. Either function will generate an array of blogs with blog_id.

    FYI, some debate about leaving these (kinds of) functions in the final release of WP3:
    http://core.trac.wordpress.org/ticket/13773

    "That list could exceed the typical memcached object size limit."

    At any rate, however you query the db to get the list, check each against the $blog_id and unset it($n) from the array then loop/echo out the remaining blogs($details).

    <?php
    global $blog_id;
    //$blogs = get_last_updated();
    $blogs = get_blog_list();
    if( is_array( $blogs ) ) {
    		foreach ( $blogs as $n => $blog ) {
    			if ( $blog['blog_id'] == $blog_id )
    				unset( $blogs[$n] );
    		}	?>
    	<ul>
    	<strong>Blogs</strong>
    	<?php foreach( $blogs as $details ) {
    		?><li><a href="http://<?php echo $details[ 'domain' ] . $details[ 'path' ] ?>"><?php echo get_blog_option( $details[ 'blog_id' ], 'blogname' ) ?></a></li><?php
    	}
    	?>
    	</ul>
    	<?php
    }
    ?>
  3. hauruapai
    Member
    Posted 4 years ago #

    thank you dsader - that code works beautifully.

    I also appreciate the link and can see why it may call problems... will have to think more about implementing this :D

    Once again, thank you for your help

Topic Closed

This topic has been closed to new replies.

About this Topic