2014-02-19 39 views
1

我想让我的主题的用户可以通过主题自定义API来替换横幅。我有它的工作,然而,默认的图像显示为空白,当我点击“查看页面源代码”我得到如下:默认图像显示为空 - WordPress主题自定义API

<img src=" " alt="banner" /> 

的默认图像中的API窗口中预览显示出来,而不是在浏览器。当我上传横幅替换默认横幅时,它完美地工作。但我无法获得默认图像出现。难道我做错了什么?

这是我的functions.php:

// Start New Section for Images 
$wp_customize->add_section('customtheme_images', array(
'title' => _('Images'), 
'description' => 'Change Images' 
)); 
$wp_customize->add_setting('banner_image', array(
'default' => 'http://mywebsite.com/banner.jpg', 
)); 
$wp_customize->add_control(new WP_Customize_Image_Control ($wp_customize, 'banner_image', array(
'label' => _('Change Banner'), 
'section' => 'customtheme_images', 
'settings' => 'banner_image' 
))); 

而且,这是我的header.php里面:

<img src="<?php echo get_theme_mod('banner_image'); ?>" alt="banner"> 

是的,我有特里普尔检查默认图像的路径,它是有效的。请帮忙!

回答

3

使用$wp_customize->add_setting('banner_image', array( 'default' => 'http://mywebsite.com/banner.jpg', ));时,默认值不会保存到数据库中(直到您保存为止)。

所以,你将不得不使用:<img src="<?php echo get_theme_mod('banner_image','http://mywebsite.com/banner.jpg'); ?>" alt="banner">

您所描述的问题是某种相关:https://wordpress.stackexchange.com/questions/129479/alternatives-to-handle-customizer-settings

+0

感谢。但是,如果我们需要设置默认值custom。那么'default'参数意义不大。 – maheshwaghmare

相关问题