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;
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 )
You can also use the get_blog_details function:
The code is as follows:
$current_blog = get_blog_details();
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的信息更多
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/");
If you use a subdomain name, use:
Code As follows:
$blog_id = get_blog_id_from_url("blog1.example.com");
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!

Can learn WordPress within three days. 1. Master basic knowledge, such as themes, plug-ins, etc. 2. Understand the core functions, including installation and working principles. 3. Learn basic and advanced usage through examples. 4. Understand debugging techniques and performance optimization suggestions.

WordPress is a Content Management System (CMS). It provides content management, user management, themes and plug-in capabilities to support the creation and management of website content. Its working principle includes database management, template systems and plug-in architecture, suitable for a variety of needs from blogs to corporate websites.

WordPressisgoodforvirtuallyanywebprojectduetoitsversatilityasaCMS.Itexcelsin:1)user-friendliness,allowingeasywebsitesetup;2)flexibilityandcustomizationwithnumerousthemesandplugins;3)SEOoptimization;and4)strongcommunitysupport,thoughusersmustmanageper

Wix is suitable for users who have no programming experience, and WordPress is suitable for users who want more control and expansion capabilities. 1) Wix provides drag-and-drop editors and rich templates, making it easy to quickly build a website. 2) As an open source CMS, WordPress has a huge community and plug-in ecosystem, supporting in-depth customization and expansion.

WordPress itself is free, but it costs extra to use: 1. WordPress.com offers a package ranging from free to paid, with prices ranging from a few dollars per month to dozens of dollars; 2. WordPress.org requires purchasing a domain name (10-20 US dollars per year) and hosting services (5-50 US dollars per month); 3. Most plug-ins and themes are free, and the paid price ranges from tens to hundreds of dollars; by choosing the right hosting service, using plug-ins and themes reasonably, and regularly maintaining and optimizing, the cost of WordPress can be effectively controlled and optimized.

The core version of WordPress is free, but other fees may be incurred during use. 1. Domain names and hosting services require payment. 2. Advanced themes and plug-ins may be charged. 3. Professional services and advanced features may be charged.

WordPress is easy for beginners to get started. 1. After logging into the background, the user interface is intuitive and the simple dashboard provides all the necessary function links. 2. Basic operations include creating and editing content. The WYSIWYG editor simplifies content creation. 3. Beginners can expand website functions through plug-ins and themes, and the learning curve exists but can be mastered through practice.

People choose to use WordPress because of its power and flexibility. 1) WordPress is an open source CMS with strong ease of use and scalability, suitable for various website needs. 2) It has rich themes and plugins, a huge ecosystem and strong community support. 3) The working principle of WordPress is based on themes, plug-ins and core functions, and uses PHP and MySQL to process data, and supports performance optimization.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools