正在寻找有关自定义程序问题的帮助。我正在使用以下代码创建一个自定义程序,它将允许我上传一张本周主题部分的图像。但是,以下代码似乎工作不正常,并且没有显示图像。Plzz帮助伙计们。。
这是我在中使用的函数functions.php
/****************************************************/
/* Topic of the Week Thumb Uploader */
/***************************************************/
function cult_customizer_register( $wp_customize ) {
$wp_customize->add_section( \'cult_topic_thumb\' , array(
\'title\' => __( \'Topic of the Week\' ),
\'priority\' => 36,
\'description\' => \'Allows you to upload an image for your topic of the week section.\',
) );
$wp_customize->add_setting( \'cult_custom_settings[display_topic_thumb]\' );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, \'cult_custom_settings[display_topic_thumb]\', array(
\'label\' => __( \'Display Topic of the Week Thumb\' ),
\'section\' => \'cult_topic_thumb\',
\'settings\' => \'cult_custom_settings[display_topic_thumb]\',
) ) );
}
add_action(\'customize_register\', \'cult_customizer_register\');
这是我的密码
index.php 用于使用自定义程序
<!-- topic of the week -->
<div class="topic_week">
<h1 class="section_heading"> TOPIC OF THE WEEK </h1>
<?php if ( get_theme_mod( \'cult_custom_settings[display_topic_thumb]\' ) ) : ?>
<div class="photo">
<a href=\'<?php echo esc_url( home_url( \'/\' ) ); ?>\' rel=\'home\'><img src=\'<?php echo esc_url( get_theme_mod( \'cult_custom_settings[display_topic_thumb]\' ) ); ?>\' alt=\'<?php echo esc_attr( get_bloginfo( \'name\', \'display\' ) ); ?>\'></a>
</div>
<?php else : ?>
<?php endif; ?>
</div>
最合适的回答,由SO网友:Amit Mishra 整理而成
嘿,只需像这样更改代码
function cult_customizer_register( $wp_customize ) {
$wp_customize->add_section( \'cult_topic_thumb\' , array(
\'title\' => __( \'Topic of the Week\' ),
\'priority\' => 36,
\'description\' => \'Allows you to upload an image for your topic of the week section.\',
) );
$wp_customize->add_setting( \'display_topic_thumb\' );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, \'display_topic_thumb\', array(
\'label\' => __( \'Display Topic of the Week Thumb\' ),
\'section\' => \'cult_topic_thumb\',
\'settings\' => \'display_topic_thumb\',
) ) );
}
add_action(\'customize_register\', \'cult_customizer_register\');
在你的索引中。php调用diplay\\u topic\\u thumb
<div class="topic_week">
<h1 class="section_heading"> TOPIC OF THE WEEK </h1>
<?php if ( get_theme_mod( \'display_topic_thumb\' ) ) : ?>
<div class="photo">
<a href=\'<?php echo esc_url( home_url( \'/\' ) ); ?>\' rel=\'home\'><img src=\'<?php echo esc_url( get_theme_mod( \'display_topic_thumb\' ) ); ?>\' alt=\'<?php echo esc_attr( get_bloginfo( \'name\', \'display\' ) ); ?>\'></a>
</div>
<?php else : ?>
<?php endif; ?>
</div>
这对你很有用