有没有什么方法可以只使用一个url动态更改页面模板,我想在演示主题中使用它,例如,当用户输入一个以结尾的特定url时,例如
?自定义\\u page\\u模板
它会动态更改模板?
这种技术是否可以用于动态更改主题(或者可能是子主题)以用于演示目的?
有没有什么方法可以只使用一个url动态更改页面模板,我想在演示主题中使用它,例如,当用户输入一个以结尾的特定url时,例如
?自定义\\u page\\u模板
它会动态更改模板?
这种技术是否可以用于动态更改主题(或者可能是子主题)以用于演示目的?
滤器pre_option_stylesheet
. 未测试的示例代码:
add_filter( \'pre_option_stylesheet\', \'wpse_100854_switch_stylesheet\' );
function wpse_100854_switch_stylesheet( $false )
{
if ( empty ( $_GET[\'theme\'] )
return $false;
$themes = wp_get_themes( array( \'allowed\' => true ) );
if ( isset ( $themes[ $_GET[\'theme\'] ] ) )
return $_GET[\'theme\'];
return $false;
}
URL应如下所示example.com/?theme=theme_directory_slug
.要仅更改特定页面的模板,请连接到template_include
:
add_filter( \'template_include\', \'wpse_100854_switch_template\' );
function wpse_100854_switch_template( $template )
{
if ( empty ( $_GET[\'template\'] )
return $false;
// do not allow to break out of the directory
$new = ltrim( $_GET[\'template\'], \'.\' );
$path = get_template_directory() . "/templates/$new.php";
if ( file_exists( $path ) )
return $path;
return $template;
}
现在添加目录templates
你的主题。当有人要求时example.com/?template=blue
和模板blue.php
存在于特殊目录中,将使用它。所以,我有一个子主题,里面除了所需的CSS文件之外什么都没有。一旦我激活了这个儿童主题,我的整个网站就关闭了。最后我有两个问题:激活一个只有CSS的子主题怎么能破坏我的网站</我怎样才能回到我原来的主题</这些是网站给我的错误:Warning: require_once(/wp-content/themes/interio_child/admin/options-framework.php) [function.require-once]: 无法打开流:中没有此类文件或目录/wp-c