使用自定义API对我很有用。我在名为inc的新文件夹中创建了一个名为customize的新文件。php
在该文件中,我添加了以下代码:
<?php
function gramophone_customize_register($wp_customize){
// Showcase Section
$wp_customize->add_section(\'showcase\', array(
\'title\' => __(\'Showcase\', \'gramophone\'),
\'description\' => sprintf( __(\'Options for showcase area\', \'gramophone\')
),
\'priority\' => 130,
));
// Image Setting
$wp_customize->add_setting(\'showcase_image\', array(
\'default\' => get_bloginfo(\'template_directory\') . \'img/Gramophonebannernew2.jpg\',
\'type\' => \'theme_mod\'
));
// Image Control
$wp_customize->add_control( new WP_Customize_Image_Control($wp_customize, \'showcase_image\', array(
\'label\' => __(\'Background Image\', \'gramophone\'),
\'section\' => \'showcase\',
\'settings\' => \'showcase_image\',
\'priority\' => 1,
)));
}
add_action(\'customize_register\',\'gramophone_customize_register\');
然后在我的函数中。php我添加了此代码
require get_template_directory(). \'/inc/customizer.php\';
我的in标题。php我为jumbotron添加了样式
<style>
.jumbotron{
margin: 0;
}
.showcase{
background:url(<?php echo get_theme_mod(\'showcase_image\', get_bloginfo(\'template_url\').\'/img/Gramophonebannernew2.jpg\'); ?>) no-repeat center center;
background-size: cover;
height: 100vh;
}
</style>
最后在我的jumbotron中添加了showcase类
<div class="jumbotron showcase">
</div>
现在,当我进入定制器时,我可以将图像更改为我想要的任何图像。如果未选择图像,则将默认图像放置在自定义程序中。将使用php。