- Download and unzip files. Or install multi-device-switcher using the WordPress plugin installer. In that case, skip 2.
- Upload “multi-device-switcher” to the “/wp-content/plugins/” directory.
- Activate the plugin through the ‘Plugins’ menu in WordPress.
- Upload a separate theme to the “/wp-content/themes/” directory.
- Go to the “Multi Device Switcher” options page through the ‘Appearance’ menu in WordPress.
- Configure settings to your needs. Select Theme by Theme option. Add and fix UserAgent by UserAgent option if necessary.
- 好好享受吧!
How to add the Custom Switcher
- Go to the “Multi Device Switcher” options page through the ‘Appearance’ menu in WordPress.
- Enter the name of the Custom Switcher (20 characters max, alphanumeric) to the ‘Add Custom Switcher’. Push the button ‘Add’.
- Configure settings. Select Theme by Theme option. Add UserAgent by UserAgent option.
- 好好享受吧!
Setting and Using the PC Switcher
There are three ways how to Using the PC Switcher.
1. Add a PC Switcher to the footer
- Go to the “Multi Device Switcher” options page through the ‘Appearance’ menu in WordPress.
- Configure settings. Check the checkbox ‘Add a PC Switcher to the footer.’ by PC Switcher option.
- 好好享受吧!
2. Add a PC Switcher to your sidebars/widget areas
- Add-on the widget ‘PC Switcher’, when you activate the plugin “Multi Device Switcher”.
- Go to the “Widgets” options page through the ‘Appearance’ menu in WordPress.
- Drag and drop the title bars ‘PC Switcher’ into the desired area.
- 好好享受吧!
3. For the theme authors and developers, add a PC Switcher to your theme.
-
Add the following code into the PHP files, when you develop your theme.
- 好好享受吧!
Using default CSS and customized CSS
- Go to the “Multi Device Switcher” options page through the ‘Appearance’ menu in WordPress.
- Configure settings. Check the checkbox ‘Add a default CSS.’ by PC Switcher option. If you want to customize CSS, uncheck the checkbox.
- 好好享受吧!
You can design the PC Switcher in the Style Sheet.
HTML output of the PC Switcher
<div class="pc-switcher"><span class="active">Mobile</span><a href="http://DOMEIN/PATH/TO/?pc-switcher=1">PC</a></div>
HTML output of the PC Switcher when switched
<div class="pc-switcher"><a href="http://DOMEIN/PATH/TO/?pc-switcher=0">Mobile</a><span class="active">PC</span></div>
How to use the Display Switcher Shortcode
The Display Switcher Shortcode switch the content of the post or page through the detection of the device.
Add the shortcode [multi]
in a post or page and use the device
attribute to device name. if the device attribute is empty, detect the desktop PC.
属性
device
(string | empty) The name of the device
- smart
- 平板电脑
- 手机
- 游戏
- the name of the Custom Switcher
if empty, detect the desktop PC
Example Shortcode
[multi]pc or other specific stuff here[/multi]
[multi device="smart"]smartphone specific stuff here[/multi]
[multi device="tablet"]tablet specific stuff here[/multi]
[multi device="test"]test Custom Switcher specific stuff here[/multi]
For theme or plugin developers. Filters The Display Switcher Shortcode through hooks. In that case, edit theme or plugin files.
<?php
echo do_shortcode('[multi device="smart"]smartphone specific stuff here[/multi]');
?>
How to use the Disable Switcher
The Disable Switcher disable the switching of the theme by a particular URL. If you match the access the url and a string or a regular expression (Regex mode), disable the switching of the theme. Regex mode is for advanced users.
- Go to the “Multi Device Switcher” options page through the ‘Appearance’ menu in WordPress.
- Enter the path to the line by line where you want to disable by Disable Switcher option. Check the checkbox ‘Enable Regex’, if you want to use a regular expression.
- 好好享受吧!
例子
/sample-page
/2015/01/hello-world
Regex mode (in the case of regular expression)
/sample-
/2015/01
UserAgent option Samples
Detect the device by JavaScript
Multi Device Switcher set the Cookie that holds the state of the switch. You can get the Cookie and detect the device by JavaScript.
Cookies
-
multi-device-switcher
The name of the device is switched (value: null | device name)
-
disable-switcher
State of disabled (value: null | 1)
-
pc-switcher
State of the PC Switcher when switched (value: null | 1)
例子
<script src="http://DOMEIN/PATH/TO/jquery.cookie.js"></script>
<script>
(function($) {
$(function() {
if ( $.cookie( 'multi-device-switcher' ) == 'smart' ) {
/* smartphone specific stuff here */
} else if ( $.cookie( 'multi-device-switcher' ) == 'tablet' ) {
/* tablet specific stuff here */
} else {
/* pc or other specific stuff here */
}
});
})(jQuery);
</script>
is_multi_device() function
is_multi_device() function is a boolean function, meaning it returns either TRUE or FALSE. Works through the detection of the device by the Multi_Device_Switcher class.
用法
<?php is_multi_device('smart'); ?>
例子
<?php
if ( function_exists( 'is_multi_device' ) ) {
if ( is_multi_device('smart') ) {
/* Display and echo smartphone specific stuff here */
} elseif ( is_multi_device('tablet') ) {
/* Display and echo tablet specific stuff here */
} else {
/* Display and echo pc or other specific stuff here */
}
}
?>
参数
device name (required)
(string) The name of the device
- smart
- 平板电脑
- 手机
- 游戏
- the name of the Custom Switcher
Return Values
(boolean) Return boolean whether a particular device.
is_pc_switcher() function
is_pc_switcher() function is a boolean function, meaning it returns either TRUE or FALSE. Return the the state of PC Switcher by the Multi_Device_Switcher class. Return true if the theme has switched by the PC Switcher.
用法
<?php is_pc_switcher(); ?>
例子
<?php
if ( function_exists( 'is_pc_switcher' ) ) {
if ( is_pc_switcher() ) {
/* Theme switched by the PC Switcher. Display and echo specific stuff here */
} else {
/* Display and echo specific stuff here */
}
}
?>
参数
无
Return Values
(boolean) Return the state of PC Switcher.
is_disable_switcher() function
is_disable_switcher() function is a boolean function, meaning it returns either TRUE or FALSE. Return the state of disabled by the Multi_Device_Switcher class.
用法
<?php is_disable_switcher(); ?>
例子
<?php
if ( function_exists( 'is_disable_switcher' ) ) {
if ( is_disable_switcher() ) {
/* Disabled. Display and echo specific stuff here */
} else {
/* Display and echo specific stuff here */
}
}
?>
参数
无
Return Values
(boolean) Return the state of disabled.
Filter hooks
- multi_device_switcher/get_options
- multi_device_switcher/get_option
- multi_device_switcher/add_header_vary
- multi_device_switcher/validate_options
Action hooks
- multi_device_switcher/detect_device
Multi Device Switcher Command
The Multi Device Switcher Command is command-line tool.
Add-on the Multi Device Switcher Command, when you activate the plugin “Multi Device Switcher”. To use the Multi Device Switcher Command is WP-CLI required.
名称
wp multi-device
描述
Multi Device Switcher Command
SYNOPSIS
wp multi-device <command>
SUBCOMMANDS
add add Custom Switcher
css turn on/off default CSS
delete delete Custom Switcher
pc-switcher turn on/off PC Switcher
reset reset Settings to Default UserAgent
status get status of settings
theme get or switch a theme
useragent get or set UserAgent
For more information about the Multi Device Switcher Command, see wp help multi-device <SUBCOMMANDS>
.
评价
目前还没有评价