默认图像未显示在WP_Customize_Cropped_Image_Control的定制程序中

时间:2016-12-17 02:02:52

标签: javascript php jquery wordpress

我在自定义程序中遇到main()的问题。我设置的默认图像没有显示在您上传的Customizer的侧窗格中,当我上传新图像时,它只输出一个数字,假设是图像ID。我将WP_Customize_Cropped_Image_Control更改为WP_Customize_Cropped_Image_Control的那一刻,一切正常。默认图像和上传的图像都显示在自定义程序和预览窗口中。

在自定义程序中为默认裁剪图像设置/显示默认图像有不同的方法吗?

这是我在customizer.php中的代码:

WP_Customize_Image_Control

这是我在customizer.js中的代码:

$wp_customize->add_setting( 'bio_image', array(
    'default'           => get_template_directory_uri() . '/images/default.jpg',
    'transport'         => 'postMessage'
) );    
$wp_customize->add_control( new WP_Customize_Cropped_Image_Control( $wp_customize, 'bio_image', array(
    'label'             => __( 'Image', 'myTheme' ),
    'flex_width'        => false, 
    'flex_height'       => false,
    'width'             => 330,
    'height'            => 330,
    'settings'          => 'bio_image'
) ) );

这是我在模板文件中的代码:

wp.customize( 'bio_image', function( value ) {
    value.bind( function( newval ) {
        $('#bio-image').attr( 'src', newval );
    } );
} );

2 个答案:

答案 0 :(得分:0)

我希望此代码可以帮助您:

<img src="<?php echo esc_url(get_theme_mod('img-upload-light',''.get_template_directory_uri().'/images/edufair-light.png')); ?>" alt="<?php bloginfo('name') ?>">

由于

答案 1 :(得分:0)

当前,在使用新的WP_Customize_Cropped_Image_Control时

$ wp_customize-> add_setting('Your_option_name',array('default'=>'this_has_to_be_a_number_that_matches_an_ID_for_to_work','sanitize_callback'=>'absint',));

我只是还没有弄清楚如何将图像设置为ID ...而不是URL