【问题标题】:Default Image not showing up in Customizer for WP_Customize_Cropped_Image_ControlWP_Customize_Cropped_Image_Control 的自定义程序中未显示默认图像
【发布时间】:2016-12-17 02:02:51
【问题描述】:

我在定制器中遇到了WP_Customize_Cropped_Image_Control 的问题。我设置的默认图像不会显示在您上传的定制器的侧窗格中,当我上传新图像时,它只会输出一个数字,假设是图像 ID。当我将WP_Customize_Cropped_Image_Control 更改为WP_Customize_Image_Control 时,一切正常。默认图像和上传的图像都显示在定制器和预览窗口中。

是否有不同的方式来设置/显示定制器中默认裁剪图像的默认图像?

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

$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'
) ) );

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

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

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

<img id="bio-image" src="<?php echo get_theme_mod( 'bio_image' , get_template_directory_uri().'/images/default.jpg' ); ?>">

【问题讨论】:

  • 面临同样的问题。你找到答案了吗?

标签: javascript php jquery wordpress


【解决方案1】:

目前,当使用新的 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

【讨论】:

  • 您的答案需要更清晰。建议给出准确的答案。
  • code$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', ));code
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-16
  • 2019-03-20
  • 2014-03-12
  • 1970-01-01
相关资源
最近更新 更多