我试图在wp admin菜单的“Customize”部分创建一些额外的主题选项。我想提供一个加载替代样式表的选项。
问题:我如何调整以下代码,用用户选择的选项替换样式表名称“posts.css”?
function theme_styles()
{
// Register the style like this for a theme:
// (First the unique name for the style (custom-style) then the src,
// then dependencies and ver no. and media type)
wp_register_style( \'custom-style\',
get_template_directory_uri() . \'/posts.css\',
array(),
\'20120208\',
\'all\' );
// enqueing:
wp_enqueue_style( \'custom-style\' );
}
add_action(\'wp_enqueue_scripts\', \'theme_styles\');
这是我遇到麻烦的特定代码行-我已经尝试过了,其中“posts”是一个主题选项和“style”。“css”是默认值,但它提供了一个空白页面:
get_template_directory_uri() . \'/<?php echo get_theme_mod( \'posts\', \'style.css\' ); ?>\',
这就是我在wp菜单中添加备用样式表选项的方式,以备不时之需:
$wp_customize->add_setting( \'posts\', array(
\'default\' => \'style.css\',
) );
$wp_customize->add_control( \'posts\', array(
\'label\' => \'Post Blocks\',
\'section\' => \'themedemo_demo_settings\',
\'type\' => \'select\',
\'choices\' => array(
\'style.css\' => \'Default\',
\'posts.css\' => \'No blocks\',
),
) );
谢谢