但我似乎不知道如何获得$样式表。
容易的
$themes = search_theme_directories();
// a random theme
$themename = array_rand($themes,1);
// that random theme\'s stylesheet
$stylesheet = content_url(\'/themes/\'.$themes[$themename][\'theme_file\']);
// The absolute path to that theme\'s stylesheet
$stylepath = WP_CONTENT_DIR.\'/themes/\'.$themes[$themename][\'theme_file\'];
获取一个非儿童的随机主题更为复杂。不过,我想就是这样了。它在测试中有效,但不认为经过严格测试。
$themes = search_theme_directories();
$rand_theme = false;
while (!$rand_theme) {
if (empty($themes)) {
break;
}
$themename = array_rand($themes,1);
$theme_obj = wp_get_theme($themename);
// Parent themes don\'t have a \'Template\'
$template = $theme_obj->get(\'Template\');
if (empty($template)) {
$rand_theme = $themename;
break;
} else {
unset($themes[$themename]);
}
}
switch_theme($rand_theme);
wp_get_theme
返回主题对象。我设置
$rand_theme
主题名称,因为这是
switch_theme
期望值。
按原样,这将在每次页面加载时切换主题。把它放到插件目录中,你就有了一个非常讨厌的插件:)