WordPress多站點獲取當前博客信息

http://www.utubon.com/1495/wordpress-multisite-get-current-bolg-infodom

 

global $current_blog;

它的返回結果是:wordpress

stdClass Object
(
    [blog_id] => 3
    [site_id] => 1
    [domain] => demo.utubon.com
    [path] => /neighborhood/
    [registered] => 2013-08-01 10:31:03
    [last_updated] => 2013-08-01 02:31:03
    [public] => 1
    [archived] => 0
    [mature] => 0
    [spam] => 0
    [deleted] => 0
    [lang_id] => 0
)

也能夠使用get_blog_details函數:函數

$current_blog = get_blog_details();

它的返回結果是:post

stdClass Object
(
    [blog_id] => 3
    [site_id] => 1
    [domain] => demo.utubon.com
    [path] => /neighborhood/
    [registered] => 2013-08-01 10:31:03
    [last_updated] => 2013-08-01 02:31:03
    [public] => 1
    [archived] => 0
    [mature] => 0
    [spam] => 0
    [deleted] => 0
    [lang_id] => 0
    [blogname] => Neighborhood
    [siteurl] => http://demo.utubon.com/neighborhood
    [post_count] => 
)
// 比global $current_blog的信息更多

這基本上就知足了咱們的須要,不過還有一個比較繞彎子的方法,使用get_blog_id_from_url函數。若是你的多站點是使用子目錄的形式,就使用:url

$blog_id = get_blog_id_from_url("example.com", "/blog1/");

若是使用的是子域名的形式,就使用:spa

$blog_id = get_blog_id_from_url("blog1.example.com");

而上面的這些參數,咱們能夠使用$_SERVER['SERVER_NAME']$_SERVER["REQUEST_URI"]獲取。blog

得到$blog_id以後各類事情就好辦了。get

相關文章
相關標籤/搜索