简体   繁体   中英

“Theme Customizer” - different background image for different category

I'm trying to make setting in theme customizer which will allow me to choose different background image to different category. I have two settings working separately, but i don't know how to combine them to work together and it seems like there was no problem like this before.

In theme customizer it looks like > this < .

How make it work together?

EDIT:

I was trying in many ways to acomplish this, but only thing that worked as i wanted was creating a section for each category and add background image there, like this:

    $wp_customize->add_section( 'background_section_cat_a', array(
        'title'         => __( 'Category: cat_a', 'twentythirteen-child'),
        'description'   => 'Options prepared to change background settings', 'twentythirteen-child',
        'priority'      => 160,
        'panel'         => 'background_panel',
        ));
    $wp_customize->add_setting( 'background_image_cat_a',   array(
        'default'       => 'abc.jpg',
    ));
    $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'background_image_cat_a', array(
               'label'      => __( 'Select background image', 'twentythirteen-child' ),
               'section'    => 'background_section_cat_a',
               'settings'   => 'background_image_cat_a',
    )));

and use this setting:

    body.category-cat-a {
        background-image: url(<?php echo get_theme_mod('background_image_cat_a'); ?>);}

But when I add new category, I have to enter my theme customizer options and add it there, and it is very time time consuming.

还有另一种方法:1.将带有图像的自定义字段添加到“类别”分类中2.在“ category.php”页面中调用图像。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM