自定义对象标题背景图像问题(HTML到WordPress)



我正在尝试将html模板转换为更易于编辑的wordpress,为此,我确实尝试将首页滑块图像和内容添加到自定义对象中。喜欢为用户轻松编辑。用户可以转到外观>gt;自定义>gt;主页hader>gt;然后他/她可以为滑块背景和内容选择图像,一切对我来说都很好,但背景图像对我来说不起作用,查询返回一些数字,比如11或16,但它应该返回图像URL。HTML模板:https://www.free-css.com/free-css-templates/page262/cron下方显示代码

转换为函数.php

$wp_customize->add_panel( 'landing_panel',
array(
'title' =>  'Landing Panel' ,
'priority' => 10, // Not typically needed. Default is 160
'capability' => 'edit_theme_options', // Not typically needed. Default is edit_theme_options
));
$wp_customize->add_section( 'landing_page_background',
array(
'title' => 'Home Background' ,
'description' => __( 'Home Background Customizer ' ),
'panel' => 'landing_panel', // Only needed if adding your Section to a Panel
'priority' => 2,
)); 
//Background Image
$wp_customize->add_setting( 'sample_default_media',
array(
'default' => get_theme_file_uri('template_url'). 'imagesbanner.png',

)
);

$wp_customize->add_control( new WP_Customize_Media_Control( $wp_customize, 'sample_default_media',
array(
'label' => 'Background Image',
'description' => esc_html__( 'This is the description for the Media Control' ),
'section' => 'landing_page_background',
'priority' => 1,

)
)
);

进入首页.php

style="background-image:url(<?php echo get_theme_mod('sample_default_media', get_theme_file_uri('template_url'). 'imagesbanner.png'); ?>) "

输出:background-image:url(11)我确实在inspect中检查了它,它被认为是类似wp-content/images/banner.png等的url

它适用于我使用

<?php 
$img_id = get_theme_mod('sample_default_media');
$img= wp_get_attachment_url( $img_id );
?>
style="background-image:url(<?php echo $img; ?>) 

最新更新