我最近也遇到了类似的情况,制作了一个引导旋转木马动态。
这是我的功能。php代码:
//Images Slider
function themename_slider_home_images_setup($wp_customize)
{
$wp_customize->add_section(\'home-slider-images\', array(
\'title\' => \'Home Slider\',
));
$wp_customize->add_setting(\'home-slider-first-image\');
$wp_customize->add_control(
new WP_Customize_Image_Control(
$wp_customize,
\'home-slider-first-image\',
array(
\'label\' => __( \'First Image\', \'theme_name\' ),
\'section\' => \'home-slider-images\',
\'settings\' => \'home-slider-first-image\'
)
)
);
$wp_customize->add_setting(\'home-slider-second-image\');
$wp_customize->add_control(
new WP_Customize_Image_Control(
$wp_customize,
\'home-slider-second-image\',
array(
\'label\' => __( \'Second Image\', \'theme_name\' ),
\'section\' => \'home-slider-images\',
\'settings\' => \'home-slider-second-image\'
)
)
);
$wp_customize->add_setting(\'home-slider-third-image\');
$wp_customize->add_control(
new WP_Customize_Image_Control(
$wp_customize,
\'home-slider-third-image\',
array(
\'label\' => __( \'Third Image\', \'theme_name\' ),
\'section\' => \'home-slider-images\',
\'settings\' => \'home-slider-third-image\'
)
)
);
}
add_action(\'customize_register\', \'themename_slider_home_images_setup\');
对于模板文件:
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="<?php echo get_theme_mod(\'home-slider-first-image\');?>" alt="Sinan" >
</div>
<div class="item header-image">
<img src="<?php echo get_theme_mod(\'home-slider-second-image\');?>" alt="Sinan" >
</div>
<div class="item header-image">
<img src="<?php echo get_theme_mod(\'home-slider-third-image\');?>" alt="Sinan" >
</div>
</div>
<!-- Left and right controls -->
</div>
我打赌有更多优雅的方法可以做到这一点,但我对WordPress自定义主题开发也很陌生,这对我来说很有帮助。
编辑:您可以使用相同的逻辑使其他内容可编辑,例如alt属性、为幻灯片添加标题等。方法是在函数文件中添加更多设置,并将HTML硬编码属性值替换为将出现在自定义程序中的适当PHP标记。
希望这有帮助!