Problem in using Customizer

时间:2014-12-16 作者:Raunak Hajela

正在寻找有关自定义程序问题的帮助。我正在使用以下代码创建一个自定义程序,它将允许我上传一张本周主题部分的图像。但是,以下代码似乎工作不正常,并且没有显示图像。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>
enter image description here

1 个回复
最合适的回答,由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>
这对你很有用

结束

相关推荐

每页完全不同的Functions.php?

是否可以通过条件加载完全不同的函数?i、 函数中的e。php您有一个条件加载在旧函数的include中,然后有另一个条件加载在新函数中?这样做的原因是一个网站正在呈现新的面貌,但只是一页一页,旧的样式和功能很混乱,需要更换,但我不能只是删除它们,因为网站的其余部分将失败。