WPMU Functions/switch to blog

来自WordPress中文文档
Bot讨论 | 贡献2010年7月23日 (五) 11:08的版本 (1个修订)
跳转至: 导航搜索

Description

Switches the active blog until the user calls the restore_current_blog() function. This function is useful if you need to pull posts, or other information, from other blogs, you can then switch back after using restore_current_blog().

Parameters

tt$new_blog/tt
(integer) (required) The id of the blog you want to switch to.
Default: Nonenoinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

Notes

This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki检查到模板循环:模板:Parameter/nowiki/pre 检查到模板循环:模板:Parameter

The usage of this template is below: prenowiki检查到模板循环:模板:Parameter/nowiki/pre Let's take a closer look at the parameters..

name
The name of the parameter.
datatype
The datatype that should be given for this parameter when called.
  • string
  • integer
  • boolean
  • mixed
description
A short description of the parameter.
importance
Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
  • required
  • optional
default
If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.

wordpress.org.cn /div /noinclude

Return Values

tt(boolean)/tt 
True on success, false if new_blog was blank, or if you tried to switch to the blog you're on.
tt(global)/tt 
Sets up a global variable called: switched.

Usage

%%%?php switch_to_blog($new_blog) ?%%%

Examples

%%%?php

   global $switched;
   switch_to_blog(7);
   echo 'You switched from blog ' . $switched . ' to 7';
   restore_current_blog();
   echo 'You switched back.';

?%%%

Related Functions

To easily revert back to the blog you were on, restore_current_blog()