php - 如何为 WordPress 多个子域设置 if-else 条件?
问题描述
此代码在我的 wordpress 网站页面上运行良好。
<?php
if ( is_page('pt') ) {
$language = 'pt';
}
else if( is_page('es') ) {
$language = 'es';
}
else {
$language = 'en';
}
?>
<?php echo $language; ?>
我在主域下有 4 个子域。
喜欢:
- 示例.domain.com
- example1.domain.com
- example2.domain.com
我想对子域应用相同的编码方法。
例如:
<?php
if ( is subdomain example.domain.com ) {
$language = 'pt';
}
else if( is subdomain example1.domain.com ) {
$language = 'es';
}
else if( is subdomain example2.domain.com ) {
$language = 'ar';
}
else {
$language = 'en';
}
?>
如何为与 WordPress is_page 条件相同的子域打印变量。
解决方案
<?php
if(isset($_SERVER['HTTPS'])){
$domain = $_SERVER['HTTPS_HOST'];
switch($domain){
case 'example.domain.com': Your code...;
break;
case 'example1.domain.com': Your code...;
break;
case 'example2.domain.com': Your code...;
break;
default: Your code...;
}
}
推荐阅读
- acumatica - 如何添加到自定义图形活动按钮?
- c - 可能由 strcpy 引起的 HardFault
- bash - 删除每次登录后我得到的 -Bash 错误
- python - python中线图上的数据光标
- c++ - 尝试在 C++ 中的 Windows 上进行一些基本的套接字编程并遇到库文件问题
- javascript - 无法访问 useReducer 值,返回空数组
- ionic-framework - 错误错误:未捕获(承诺):NullInjectorError:R3InjectorError(RegisterPageModule)[AccessProviders - > AccessProviders]
- c - exit(21) 代表什么?可以用 exit(1) 代替吗?
- c# - 使用实体框架将日期作为字符串传递给 Crystal Report
- excel - 如何将变量从表单传递到工作簿 VBA