The method of obtaining current blog information from multiple sites of wordpress blog
Xiaobian to share with you about wordpress blog multi-site access to the current blog information method, I hope you read this article after the harvest, let us discuss it together!
How do I get my current blog information?
Wordpress Blog Multi-site Get current blog information sample
After launching WordPress multi-site, you may need to get current blog information in the plugin. This article helps you solve this problem.
First of all, what is the current blog?
Unlike a single site, Multisite produces multiple blogs, called blogs, or subsites (including the main site). And the subsite you visit becomes the current blog. The information of the current blog mainly refers to the unique information of the blog itself, such as the name, path, ID number of the blog, and does not include how many users and how many articles the blog has. Users and articles can be obtained by obtaining the ID number after the current blog information.
The current blog information can be obtained in the plugin like this:
The code is as follows:
global $current_blog;
Its return result is:
The code is as follows:
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)
You can also use the get_blog_details function:
The code is as follows:
$current_blog = get_blog_details();
Its return result is:
The code is as follows:
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] => )//More information than global $current_blog
This basically meets our needs, but there is a more roundabout way, using the get_blog_id_from_url function. If your multi-site is in the form of subdirectories, use:
The code is as follows:
$blog_id = get_blog_id_from_url("example.com", "/blog1/");
If you are using a subdomain name, use:
The code is as follows:
$blog_id = get_blog_id_from_url("blog1.example.com");
The above parameters can be obtained using $_SERVER <$'SERVER_NAME'] and $_SERVER <$'REQUEST_URI'].
After you get $blog_id, everything is easy.
After reading this article, I believe you have a certain understanding of the wordpress blog multi-site access to the current blog information method, want to know more relevant knowledge, welcome to pay attention to the industry information channel, thank you for reading!