Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of obtaining current blog information from multiple sites of wordpress blog

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report