我想检测子域是否为“m”,如果是,则显示不同的模板。找不到我在找的东西,在Wordpress API中这样做。在Wordpress插件中更改模板
1
A
回答
0
可以使用parse_url()函数在PHP中做到这一点:
$parsed = parse_url($_SERVER['HTTP_HOST']);
$host = explode('.', $parsedUrl['host']);
$subdomain = $host[0];
然后,您可以添加自己的if语句:
if ($subdomain == "m") { ... } else { ... }
+0
寻找像'wp_switch_template('theme_name');'= 3 – user1139252 2012-01-09 21:31:05
+0
就我所知这并不存在。只需使用上面的IF语句在标题中加载不同的样式表,或者如果它比这更复杂,则可能需要考虑使用WP的网络/多站点功能。 – Justin 2012-01-09 21:49:17
0
您应该使用 'template_redirect' 过滤器,或其中一个模板过滤器用于更改正在加载的模板。
0
我建议创建你自己的插件用一个简单的脚本,并把它的wp-content有这样的代码/插件:
<?php
/**
* Plugin Name: Theme swithwer
* Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
* Description: Custom theme switcher
* Version: 0.1
* Author: XXX XXX
* Author URI: http://URI_Of_The_Plugin_Author
* License: A "Slug" license name e.g. GPL2
*/
add_filter('stylesheet', 'switch_ma_theme');
add_filter('template', 'switch_ma_theme');
function switch_ma_theme()
{
global $wpdb;
// condition to test ad theme to load
if ($_SERVER['HTTP_HOST'] == 'blog.xxxx.xxx')
return 'xxxthemexxx';
// else default theme
$theme = $wpdb->get_results("SELECT option_value FROM wp_options where option_name='template' ");
$theme = array_pop($theme);
return $theme->option_value;
// Return the theme directory name
}
然后在管理走,找你新的插件并启用它
相关问题
- 1. 在wordpress中更改插件模板
- 2. 在wordpress模板中更改google标记
- 3. 将WordPress模板更改为
- 4. wordpress:更改页面模板
- 5. WordPress页面模板在更新时更改回默认模板
- 6. 更改Wordpress模板中的链接
- 7. 更改模板中的语言并更改wordpress中的模板样式
- 8. 更改wordpress插件功能
- 9. 通过url更改WordPress模板参数
- 10. 更改Wordpress木材模板位置
- 11. 更改WordPress的模板层次
- 12. 更新wordpress模板
- 13. WordPress的插件模板覆盖 - 组合
- 14. 革命滑块模板 - WordPress插件
- 15. wordpress插件的自定义模板
- 16. 插件内的模板 - WordPress的
- 17. WordPress通过插件添加模板
- 18. 访问Wordpress插件的模板方法
- 19. 在wordpress模板或小部件中使用插件的功能
- 20. 将Gridster插入WordPress模板
- 21. 如何使插件在wordpress中的每个模板中工作
- 22. 更改文件的模板
- 23. 试图修改wordpress模板
- 24. 修改WordPress评论模板
- 25. WordPress如何在自定义插件中创建模板和url
- 26. 在儿童主题的页面模板中使用wordpress插件
- 27. 在自定义模板中启用Wordpress Events Plus插件简码
- 28. 如何在wordpress模板中放置插件钩
- 29. 是否可以在页面模板中添加wordpress插件?
- 30. 在WordPress模板
如果你想暂时*在活动HTTP请求上使用不同的模板,你需要['template_include' filter](https://codex.wordpress.org/Plugin_API/Filter_Reference/template_include)。如果您想*保留更改,以便将来用于所有请求,则需要直接更新'wp_options'表中的'template'和'stylesheet'选项。请注意['template'和'stylesheet'不相同](https://wordpress.stackexchange.com/a/40220/10388)。 – rinogo 2017-09-26 20:33:49
另请参阅[switch_theme()](https://developer.wordpress.org/reference/functions/switch_theme/)。看起来很多不同的选项。我正在和你们一起解决这个问题! :) – rinogo 2017-09-26 20:54:20