Home > Backend Development > PHP Tutorial > WordPress multisite gets current blog information_PHP tutorial

WordPress multisite gets current blog information_PHP tutorial

WBOY
Release: 2016-07-13 10:36:34
Original
971 people have browsed it

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

global $current_blog;
Copy after login

Its return result is:

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
)
Copy after login

You can also use the get_blog_details function:

$current_blog = get_blog_details();
Copy after login

Its return result is:

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的信息更多
Copy after login

This basically meets our needs, but there is a more circuitous method, using the get_blog_id_from_url function. If your multisite uses subdirectories, use:

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

If you are using a subdomain name, use:

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

We can use $_SERVER['SERVER_NAME'] and $_SERVER["REQUEST_URI"] to obtain the above parameters.

After getting $blog_id, all kinds of things will be easier to handle.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/738537.htmlTechArticlehttp://www.utubon.com/1495/wordpress-multisite-get-current-bolg-info global $current_blog; Its return result is: stdClass Object( [blog_id] = 3 [site_id] = 1 [domain] = demo.utu...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template