Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WordPress主题自定义程序内容未显示在页面上_Php_Wordpress_Wordpress Theming - Fatal编程技术网

Php WordPress主题自定义程序内容未显示在页面上

Php WordPress主题自定义程序内容未显示在页面上,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,全部 我正在使用我为一个网站开发的自定义WordPress主题。我在页脚的左侧有一个字段,用于显示邮寄地址,我希望通过WordPress中的主题定制器可以对其进行编辑。我已经将有问题的字段添加到customizer中,但是该字段的内容没有显示在页面上 在functions.php中,以下代码将该字段添加到主题定制器中: //Adds footer address to theme customizer function sanitize_footer_address($input){

全部

我正在使用我为一个网站开发的自定义WordPress主题。我在页脚的左侧有一个字段,用于显示邮寄地址,我希望通过WordPress中的主题定制器可以对其进行编辑。我已经将有问题的字段添加到customizer中,但是该字段的内容没有显示在页面上

在functions.php中,以下代码将该字段添加到主题定制器中:

//Adds footer address to theme customizer   

function sanitize_footer_address($input){
    return strip_tags(stripslashes($input));    
}

function portfolio_customize_register($wp_customize){

    $wp_customize->add_section(
        'Footer', 
        array(
            'title' => __('Left Footer Content', 'portfolio'),
            'priority' => 200
        )
    );

    $wp_customize->add_setting(
        'footer_address', 
        array(
            'default' => '100 Main Street | Anytown, USA',
            'sanitize_callback' => 'sanitize_footer_address'
        )
    );

    $wp_customize->add_control( new WP_Customize_Control(
    $wp_customize, 
    'footer_address',
    array(
        'label' => 'Address to appear on left side of footer', 
        'section' => 'Footer', 
        'settings' => 'footer_address_text', 
        'type' => 'text'
    )
    )
 ); 
}

add_action(customize_register, portfolio_customize_register);
在footer.php模板中,相关标记为:

<p class="col md-4 text-muted" id="footer_address"><?php echo get_theme_mod('footer_address_text'); ?></p>

该字段的内容不会显示在页面上

add\u setting()
注册了错误的ID,在添加默认字段时,仅当创建了自定义的
WP\u Customize\u*
类时,才需要
新的WP\u Customize\u控件($WP\u Customize,)

$wp_customize->add_setting(
    'footer_address_text', 
    array(
        'default' => '100 Main Street | Anytown, USA',
        'sanitize_callback' => 'sanitize_footer_address'
    )
);

$wp_customize->add_control(
    'footer_address',
    array(
        'label' => 'Address to appear on left side of footer', 
        'section' => 'Footer', 
        'settings' => 'footer_address_text', 
        'type' => 'text'
    )
 ); 

谢谢,布拉索菲洛。它仍然需要新的WP_Customize_控件声明,因为这不是一个默认字段,但是纠正了您指出的ID错误修复了问题。干杯