get_blog_id_from_url()

通过博客网址获取博客id

描述

Get a blog’s numeric ID from its URL.

用法

/* ———————————-
* wordpress函数
* ———————————- */

<?php get_blog_id_from_url( $domain, $path ); ?>

参数

$domain

(string) (必填) Blog domain.

默认值: None

$path

(string) (可选) Blog path.

默认值: “/”

示例


<?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”);

?>

历史

  • 添加于 版本: 2.6.5

源文件

get_blog_id_from_url() 函数的代码位于 wp-includes/ms-functions.php

* 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

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索