我想檢測子域是否爲「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模板中更改google標記
- 2. 更改模板中的語言並更改wordpress中的模板樣式
- 3. 更改Wordpress木材模板位置
- 4. 更新wordpress模板
- 5. 插件內的模板 - WordPress的
- 6. 從插件添加模板頁面 - Wordpress
- 7. 革命滑塊模板 - WordPress插件
- 8. wordpress插件的自定義模板
- 9. 訪問Wordpress插件的模板方法
- 10. 在wordpress模板或小部件中使用插件的功能
- 11. 如何使插件在wordpress中的每個模板中工作
- 12. 更改文件的模板
- 13. 試圖修改wordpress模板
- 14. 是否可以在頁面模板中添加wordpress插件?
- 15. 在WordPress模板
- 16. 如何更改Mailchimp Wordpress小部件的模板?
- 17. 更改wordpress插件的字體
- 18. 從Wordpress插件更改字體
- 19. 如何在NetBeans中更改PHP Smarty插件模板文件擴展名?
- 20. Wordpress使用插件中的模板文件
- 21. 更改Xcode中的模板
- 22. WordPress插件更新
- 23. 更改即用型WordPress模板中元素的順序
- 24. 如何在WordPress中更改「Facebook評論插件」的顏色?
- 25. 在WordPress中更改頁面標題標籤的插件?
- 26. 如何通知WordPress插件用戶插件已更改名稱?
- 27. angularjs模式更改模板?
- 28. 在FreeMarker模板中更改子變量
- 29. 在TeamCity中更改構建模板
- 30. 在Zope模板中更改屬性
如果你想暫時*在活動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