嗨,大家好!
我需要动态更改我的主题(对于移动版本,我有不同的外观),但是小部件没有正确地保存。
我试图从主题中配置小部件,但是这个方法不起作用:
if (!function_exists('sync_widgets_config')):
function sync_widgets_config() {
static $validConf = [
'orphaned_widgets_1' => [
0 => 'search-2',
1 => 'recent-posts-2',
2 => 'recent-comments-2',
3 => 'archives-2',
4 => 'categories-2',
5 => 'meta-2',
],
'wp_inactive_widgets' => [0 => 'gin-content-categories-2',],
'sliding_sidebar' => [
0 => 'gin-login-form-3',
1 => 'gin-account-cabinet-2',
2 => 'gin-content-top-menu-2',
],
'header_area' => [0 => 'gin-top-area-2',],
'pre_content' => [0 => 'gin-content-news-slider-2',],
'global_menu' => [0 => 'gin-content-categories-3'],
'footer' => [0 => 'gin-footer_widget-2',],
'global_footer' => [0 => 'gin-siteheart_widget-2',],
];
if ($validConf == wp_get_sidebars_widgets()) {
return;
}
wp_set_sidebars_widgets($validConf);
}
sync_widgets_config();
endif; // if (!function_exists('sync_widgets_config')):您能建议一个方法(或插件)来为主题配置我的小部件,并且在我更改主题之后,小部件将以保存在主题中的形式出现吗?
发布于 2015-02-10 18:11:27
我解决了这个问题。我做了下一步:
在这两个主题中,我都注册了来自两个主题的小部件区域:
// Desktop areas
register_sidebar(array(
'name' => 'Top area',
...
));
//...
// Mobile areas
register_sidebar(array(
'name' => 'Sliding area',
...
));在此之后,我为桌面主题配置了小部件,并将小部件添加到移动小部件区域。
// If user agent is mobile, we will change theme on fly
if (wp_is_mobile()) {
add_filter('stylesheet', 'change_theme', 1);
add_filter('template', 'change_theme', 1);
}
// Return mobile theme name
function change_theme($theme)
{
return 'mobiletheme';
}https://stackoverflow.com/questions/28387177
复制相似问题