Get_Theme_mod Customizer字段中的裁剪图像

时间:2013-02-25 作者:user2014024

我使用以下代码允许用户通过定制器上载自定义图像(除了标题图像之外)。是否有方法在显示图像时裁剪图像?

$wp_customize->add_setting( \'intro-img\',
array (
\'default\' => \'http://example.com/image.png\',
)
);

$wp_customize->add_control(
new WP_Customize_Image_Control(
    $wp_customize,
    \'intro-img\',
    array(
        \'label\' => \'Intro Image\',
        \'section\' => \'section_one\',
        \'settings\' => \'intro-img\'

    )
    )
);
并显示为:

<?php echo get_theme_mod( \'intro-img\', \'http://example.com/image.png\' ); ?>

1 个回复
SO网友:JPollock

如果可能的话,用你的方法会很棘手。您可以使用具有灵活维度的自定义标题。这将允许用户上传标题图像,然后根据需要轻松裁剪。

// Register Theme Features
function custom_theme_features()  {

// Add theme support for Custom Header
$header_args = array(
    \'default-image\'          => \'http://example.com/image.png\',
    \'width\'                  => 0,
    \'height\'                 => 0,
    \'flex-width\'             => true,
    \'flex-height\'            => true,
    \'random-default\'         => false,
    \'header-text\'            => false,
    \'default-text-color\'     => \'\',
    \'uploads\'                => true,

);
add_theme_support( \'custom-header\', $header_args );
}

// Hook into the \'after_setup_theme\' action
add_action( \'after_setup_theme\', \'custom_theme_features\' );

结束