WordPress定制器未设置自定义设置或控件

时间:2017-02-22 作者:Brandon Powell

我一直在学习如何为主题创建主题定制器功能。我一直在学习如何使社交媒体图标显示在页脚上。

我已经包含了必须包含在函数中的文件。php。但在主题定制器的前端,我的设置不会显示并收到错误消息。

我正在学习,只是想看看是否可行,看看:https://www.competethemes.com/blog/social-icons-wordpress-menu-theme-customizer/#comment-20708

警告:call\\u user\\u func\\u array()要求参数1为有效回调,在/Users/brandonpowell/sites/valet/alter-theme/web/wp/wp-includes/class-wp-hook中找不到函数“rixcy\\u scripts”,或函数名无效。php第298Footer行。php

<?php
?>

<!-- #content -->
<div class="footer">
    <div class="main-content">
        <div class="width-6">
                <img src="img/AlterEgo-Branding-text-color.png">
        </div>

        <div class="width-6">

        </div>
    </div>
</div>

<div class="social">
        <div class="main-content">
                <?php require get_template_directory() . \'/inc/outputicons.php\'; ?>
        </div>
</div>


<?php wp_footer(); ?>

</body>
</html>
社会客户部门。php

  <?php
        function my_add_customizer_sections( $wp_customize ) {
    
            $social_sites = ct_atlers_social_array();
    
            // set a priority used to order the social sites
            $priority = 5;
    
            // section
            $wp_customize->add_section( \'ct_alter_social_array_filter\', array(
                \'title\'       => __( \'Social Media Icons\', \'alter\' ),
                \'priority\'    => 12,
                \'description\' => __( \'Add the URL for each of your social profiles.\', \'alter\' )
            ) );
    
            // create a setting and control for each social site
            foreach ( $social_sites as $social_site => $value ) {
    
                $label = ucfirst( $social_site );
    
                if ( $social_site == \'google-plus\' ) {
                    $label = \'Google Plus\';
                } elseif ( $social_site == \'twitter\' ) {
                    $label = \'Twitter\';
                } elseif ( $social_site == \'facebook\' ) {
                    $label = \'Facebook\';
                } elseif ( $social_site == \'Github\' ) {
                    $label = \'github\';
                } elseif ( $social_site == \'linkedin\' ) {
                    $label = \'Linkedin\';
                } elseif ( $social_site == \'youtube\' ) {
                    $label = \'Youtube\';
                } elseif ( $social_site == \'instagram\' ) {
                    $label = \'Instagram\';
                } elseif ( $social_site == \'instagram\' ) {
                    $label = \'Instagram\';
                } elseif ( $social_site == \'dribbble\' ) {
                    $label = \'dribbble\';
                } elseif ( $social_site == \'behance\' ) {
                    $label = \'behance\';
                } elseif ( $social_site == \'behance\' ) {
                    $label = \'behance\';
                } elseif ( $social_site == \'email-form\' ) {
                    $label = \'Contact Form\';
                }
                // setting
                $wp_customize->add_setting( $social_site, array(
                    \'sanitize_callback\' => \'esc_url_raw\'
                ) );
                // control
                $wp_customize->add_control( $social_site, array(
                    \'type\'     => \'url\',
                    \'label\'    => $label,
                    \'section\'  => \'ct_tribes_social_media_icons\',
                    \'priority\' => $priority
                ) );
                // increment the priority for next site
                $priority = $priority + 5;
            }
        }
        add_action( \'customize_register\', \'my_add_customizer_sections\' );
输出。php

<?php

function my_social_icons_output() {

    $social_sites = ct_atlers_social_array();

    foreach ( $social_sites as $social_site => $profile ) {

        if ( strlen( get_theme_mod( $social_site ) ) > 0 ) {
            $active_sites[ $social_site ] = $social_site;
        }
    }

    if ( ! empty( $active_sites ) ) {

        echo \'<ul class="social-media-icons">\';
        foreach ( $active_sites as $key => $active_site ) {
            $class = \'fa fa-\' . $active_site; ?>
            <li>
                <a class="<?php echo esc_attr( $active_site ); ?>" target="_blank" href="<?php echo esc_url( get_theme_mod( $key ) ); ?>">
                    <i class="<?php echo esc_attr( $class ); ?>" title="<?php echo esc_attr( $active_site ); ?>"></i>
                </a>
            </li>
        <?php }
        echo "</ul>";
    }
}
社交阵列。php

<?php
function ct_atlers_social_array() {

    $social_sites = array(
        \'twitter\'       => \'alter_twitter_profile\',
        \'facebook\'      => \'alter_facebook_profile\',
        \'google-plus\'   => \'alter_googleplus_profile\',
        \'linkedin\'      => \'alter_linkedin_profile\',
        \'youtube\'       => \'alter_youtube_profile\',
        \'instagram\'     => \'alter_instagram_profile\',
        \'dribbble\'      => \'alter_dribbble_profile\',
        \'behance\'       => \'alter_behance_profile\',
        \'github\'        => \'alter_github_profile\',
        \'email_form\'        => \'alter_email_profile\',
    );

    return apply_filters( \'ct_alter_social_array_filter\', $social_sites );
}

1 个回复
最合适的回答,由SO网友:David Lee 整理而成

这个section 您创建了\'Social Media Icons\' 不显示,因为为空,它没有任何控制,这是因为您没有设置正确的ID 在控件参数中,应该如下所示socialcustomizersection.php:

// control
$wp_customize->add_control( $social_site, array(
    \'type\'     => \'url\',
    \'label\'    => $label,
    \'section\'  => \'ct_alter_social_array_filter\', //it should be the ID you Set for the section
    \'priority\' => $priority
) );
也在footer.php 您正在加载outputicons.php 并且只包含一个函数,您需要调用function, 把这个放在require_oncefooter.php 或在outputicons.php:

my_social_icons_output();
本节将显示,我在此处添加了2个用于测试输出:

enter image description here他们的工作:

enter image description here

相关推荐