Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改Wordpress插件中的模板_Wordpress_Templates_Plugins_Themes - Fatal编程技术网

更改Wordpress插件中的模板

更改Wordpress插件中的模板,wordpress,templates,plugins,themes,Wordpress,Templates,Plugins,Themes,我想检测子域是否为“m.”,如果是,则显示不同的模板。在Wordpress API中找不到我要查找的内容。您可以使用PHP中的函数来执行此操作: $parsed = parse_url($_SERVER['HTTP_HOST']); $host = explode('.', $parsedUrl['host']); $subdomain = $host[0]; 然后,您可以添加自己的if语句: if ($subdomain == "m") { ... } else { ... } 您应该使用

我想检测子域是否为“m.”,如果是,则显示不同的模板。在Wordpress API中找不到我要查找的内容。您可以使用PHP中的函数来执行此操作:

$parsed = parse_url($_SERVER['HTTP_HOST']);
$host = explode('.', $parsedUrl['host']);
$subdomain = $host[0];
然后,您可以添加自己的if语句:

if ($subdomain == "m") { ... } else { ... }

您应该使用“模板重定向”过滤器或其他模板过滤器之一来更改正在加载的模板。

我建议您使用一个脚本创建自己的插件,并将其放入wp内容/插件中,代码如下:

<?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

}

寻找类似的
wp_开关_模板('theme_name')=3据我所知不存在的。只需使用上面的IF语句在标题中加载不同的样式表,或者如果它比这更复杂,您可能需要考虑仅使用WP的网络/多站点特性。如果您想在活动的HTTP请求上临时使用不同的模板,则需要。如果要保留更改以便在将来的所有请求中使用,则需要直接更新
wp_options
表中的
模板
样式表
选项。请注意,另请参见。看起来有很多不同的选择。我正在和你们一起解决这个问题!:)