WordPress函数文档get_blog_id_from_url()
通过博客网址获取博客id 描述 Get a blog’s numeric ID from its URL. 用…
通过博客网址获取博客id
描述
Get a blog’s numeric ID from its URL.
用法
1
2
3
4
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
<?php get_blog_id_from_url( $domain, $path ); ?>
|
参数
$domain
(string) (必填) Blog domain.
默认值: None
$path
(string) (可选) Blog path.
默认值: “/”
示例
1
2
3
4
5
6
7
8
9
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
<?php
// For subdirectory installs
$blog_id = get_blog_id_from_url(“example.com”, “/blog1/”);
// For subdomain installs
$blog_id = get_blog_id_from_url(“blog1.example.com”);
?>
|
Default Usage
历史
- 添加于 版本: 2.6.5
源文件
get_blog_id_from_url() 函数的代码位于 wp-includes/ms-functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
/**
* Get a blog’s numeric ID from its URL.
*
* On a subdirectory installation like example.com/blog1/,
* $domain will be the root ‘example.com’ and $path the
* subdirectory ‘/blog1/’. With subdomains like blog1.example.com,
* $domain is ‘blog1.example.com’ and $path is ‘/’.
*
* @since MU 2.6.5
*
* @global wpdb $wpdb
*
* @param string $domain
* @param string $path Optional. Not required for subdomain installations.
* @return int 0 if no blog found, otherwise the ID of the matching blog
*/
function get_blog_id_from_url( $domain, $path = ‘/’ ) {
global $wpdb;
$domain = strtolower( $domain );
$path = strtolower( $path );
$id = wp_cache_get( md5( $domain . $path ), ‘blog-id-cache’ );
if ( $id == –1 ) // blog does not exist
return 0;
elseif ( $id )
return (int) $id;
$id = $wpdb->get_var( $wpdb->prepare( “SELECT blog_id FROM $wpdb->blogs WHERE domain = %s and path = %s /* get_blog_id_from_url */”, $domain, $path ) );
if ( ! $id ) {
wp_cache_set( md5( $domain . $path ), –1, ‘blog-id-cache’ );
return 0;
}
wp_cache_set( md5( $domain . $path ), $id, ‘blog-id-cache’ );
return $id;
}
// Admin functions
|
- 原文:http://codex.wordpress.org/Function_Reference/get_blog_id_from_url
类别:WordPress函数文档、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
评论功能已经关闭!