如何实现主题选项将bootstrap 4容器从.tainer更改为.tainer-Fluid

时间:2018-09-23 作者:Zoran Koprek

从头开始开发wordpress主题,我获得了一些基础知识,但是,当我开始制作用于更改页面外观的模板时(比如1、2或3列,有无侧边栏…),我想到了一个主意,那就是在主题中提供选项来轻松更改引导4会很好。容器到。容器液体。

容器div从标题开始。php,以页脚结尾。php。如何在主题中实现此选项?

1 个回复
SO网友:Zoran Koprek

以下是可行的解决方案(主题名为“zoran”):

//1. Step (Create Customizer section, setting, control)

//In functions.php include or directly put code that goes something like this:



function zoran_customize_register( $wp_customize ) {
$wp_customize->add_section( \'zoran_sekcija\', array(
    \'title\'          => __( \'Zoran\', \'zoran\' ),
    \'priority\'       => 35,
) );
$wp_customize->add_setting( \'zoran_postavka\', array(
    \'default\'        => \'container\',
    \'type\' => \'theme_mod\',
    \'capability\' => \'edit_theme_options\',
) );

$wp_customize->add_control(\'zoran_control\', array(
    \'label\'   => \'Container\',
    \'section\' => \'zoran_sekcija\',
    \'settings\'   => \'zoran_postavka\',
    \'type\' => \'radio\',
    \'choices\' => array(
        \'container\' => \'Fluid\',
        \'container-fluid\' => \'Fixed\', 
    ),
) );


}
add_action( \'customize_register\', \'zoran_customize_register\' );

 //2. Step (Create javascript to manipulate class container)

 //In functions.php include or type:

function zoran_customize_js()
{
?>
     <script>
         div = document.getElementsByClassName("container");
         div[0].classList.toggle(<?php echo "\'" . get_theme_mod(\'zoran_postavka\', \'container\') . "\'"; ?>);


     </script>
<?php
}
add_action( \'wp_footer\', \'zoran_customize_js\');
我想就是这样。请提出改进建议。

preview

结束