Home > CMS Tutorial > WordPress > body text

How to get current blog information for multiple WordPress blog sites

藏色散人
Release: 2020-01-10 10:03:39
Original
2093 people have browsed it

How to get current blog information for multiple WordPress blog sites

How to get the current blog information for multiple wordpress blog sites?

Example of getting current blog information for multiple wordpress blog sites

Recommended : "wordpress tutorial"

After activating WordPress multi-site, you may need to obtain the current blog information in the plug-in. This article helps you solve this problem

First of all, what is a current blog?

Different from a single site, Multisite will generate multiple blogs, called blogs, which are subsites (including the main site). The subsite you visit is called the current blog. The information of the current blog mainly refers to the unique information of the blog itself such as the name, path, and ID number of the blog. It does not include how many users and articles the blog has. Users and articles can be obtained by obtaining the ID number after obtaining the current blog information. .

Obtaining the current blog information can be obtained in the plug-in like this:

The code is as follows:

global $current_blog;
Copy after login

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

You can also use the get_blog_details function:

The code is as follows:

$current_blog = get_blog_details();
Copy after login

The 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] => <a href="http://demo.utubon.com/neighborhood">http://demo.utubon.com/neighborhood</a>
[post_count] => 
)
// 比global $current_blog的信息更多
Copy after login

This Basically, it meets our needs, but there is a more roundabout method, using the get_blog_id_from_url function. If your multisite is in the form of a subdirectory, use:

The code is as follows:

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

If you use a subdomain name, use:

Code As follows:

$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 obtaining $blog_id, various things will be easier to handle.

The above is the detailed content of How to get current blog information for multiple WordPress blog sites. For more information, please follow other related articles on the PHP Chinese website!

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