在Wordpress的自定义主题部分添加页脚部分

pzfprimi  于 2023-03-22  发布在  WordPress
关注(0)|答案(1)|浏览(208)

我正在从头开始制作一个主题WordPress,但我如何在WordPress的自定义主题部分的左侧添加或构建页脚部分?
我们的想法是添加页脚部分并为页脚创建一个自定义徽标,但我无法在function.php中配置它。
代码:

function my_customize_register($wp_customize)
{
    $wp_customize->add_panel('mypanel', [
        'title' => __('My awesome panel', 'domain'),
        'description' => __(
            "This is the description which doesn't want to show up :(",
            'domain'
        ),
        'capability' => 'edit_theme_options',
        'priority' => 2,
    ]);

    $wp_customize->add_section('mysection', [
        'title' => __('My even more awesome section', 'domain'),
        'panel' => 'mypanel',
        'description' => __('Section description which does show up', 'domain'),
    ]);

    $wp_customize->add_setting('logo', [
        'capability' => 'edit_theme_options',
        'default' => '',
        'sanitize_callback' => 'ic_sanitize_image',
    ]);
    $wp_customize->add_control(
        new WP_Customize_Image_Control($wp_customize, 'logo', [
            'label' => __('Logo', 'text-domain'),
            'section' => 'general',
            'settings' => 'logo',
        ])
    );
}

add_action('customize_register', 'my_customize_register');
2w3kk1z5

2w3kk1z51#

注册Wp定制器。

add_action("customize_register", "logo_customizer_register");

function logo_customizer_register($wp_customize) {
    // Add Panel
    $wp_customize->add_panel('mypanel',
        array(
            'priority' => 100,
            'title' => __('Theme Options', 'themeprefix'),
            'description' => __('Theme Modifications like color, footer, header. ', 'themeprefix'),
        )
    );
    // Add Footer section
    $wp_customize->add_section('footer-section',
        array(
            'title' => __('Footer', 'themeprefix'),
            'priority' => 1,
            'panel' => 'mypanel'
        )
    );

    // Footer Logo
    $wp_customize->add_setting("custom_footer_logo", [
        "transport" => "postMessage"
    ]);
    $wp_customize->add_control(
        new WP_Customize_Cropped_Image_Control(
            $wp_customize,
            "custom_footer_logo",
            [
                "label" => __("Footer Logo", "themeprefix"),
                "flex_width" => false,
                "flex_height" => false,
                // Define height width based on your need.
                "width" => 50,
                "height" => 50,
                "settings" => "custom_footer_logo",
                "section" => "footer-section",
                "priority" => 1,
            ]
        )
    );
}

在您想要的位置显示页脚徽标。

if (get_theme_mod('custom_footer_logo')) {
    echo '<img class="footer-logo" src="'.wp_get_attachment_url(get_theme_mod('custom_footer_logo')).'">';
}

相关问题