Php Wordpress主题定制器
我对php非常陌生,真的需要一些帮助 我刚刚发现了Wordpress的主题定制器,我正在尝试将其实现到我正在创建的新主题中 我使用以下方法添加了一个背景图像选项:-Php Wordpress主题定制器,php,wordpress,Php,Wordpress,我对php非常陌生,真的需要一些帮助 我刚刚发现了Wordpress的主题定制器,我正在尝试将其实现到我正在创建的新主题中 我使用以下方法添加了一个背景图像选项:- // Upload Custom Background $wp_customize->add_setting( 'simplistic_body_bg' ); $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'sim
// Upload Custom Background
$wp_customize->add_setting( 'simplistic_body_bg' );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'simplistic_body_bg', array(
'label' => __( 'Upload a custom background image', 'simplistic' ),
'default' => 'img/bright_squares.png',
'section' => 'simplistic_background',
'settings' => 'simplistic_body_bg',
) ) );
然后在header.php中使用它
<style>
body { color: <?php echo $simplistic_body_color; ?>; background-image:url(<?php echo esc_url( get_theme_mod( 'simplistic_body_bg' ) ); ?>);}
</style>
正文{颜色:;背景图像:url();}
它确实可以工作,但是默认的回退映像不能工作,因为空的背景映像:url()仍然存在
我尝试将“before”和“after”添加到自定义设置中,但这不起作用。有人能帮我吗
我基本上需要后备bg映像选项才能工作
非常感谢:-)
接下来
我尝试了建议的编辑,但它们似乎根本没有输出默认数据。唯一有效的方法是:
<?php
$simplistic_body_color = get_option('simplistic_body_color');
$simplistic_link_color = get_option('simplistic_link_color');
$simplistic_hover_color = get_option('simplistic_hover_color');
$simplistic_icon_color = get_option('simplistic_icon_color');
$simplistic_footer_color = get_option('simplistic_footer_color');
$simplistic_tag_color = get_option('simplistic_tag_color');
$simplistic_widget_header_color = get_option('simplistic_widget_header_color');
?>
<style>
body { color: <?php echo $simplistic_body_color; ?>;}
a { color: <?php echo $simplistic_link_color; ?>; }
a:hover { color: <?php echo $simplistic_hover_color; ?>; }
.fa { color: <?php echo $simplistic_icon_color; ?>; }
.footer-wrapper { background-color: <?php echo $simplistic_footer_color; ?>; }
.tagcloud a { background-color: <?php echo $simplistic_tag_color; ?>; }
h3.widget-title { background-color: <?php echo $simplistic_widget_header_color; ?>; }
</style>
<?php if ( get_theme_mod( 'simplistic_body_bg' ) ) : ?>
<style>
body { background-image:url(<?php echo esc_url( get_theme_mod( 'simplistic_body_bg' ) ); ?>);}
</style>
<?php else : ?>
<style>
body { background-image: url(<?php bloginfo('template_url'); ?>/img/bright_squares.png);}
</style>
<?php endif; ?>
正文{颜色:;}
a{color:;}
a:悬停{color:;}
.fa{color:;}
.footer包装{背景颜色:;}
.tagcloud a{背景色:;}
h3.widget-title{背景色:;}
正文{背景图像:url();}
body{背景图像:url(/img/bright_squares.png);}
但是感觉不太干净。我不知道如何将“if else”放在一个样式括号中。作为用户3734309,您缺少添加设置的第二个参数:
$wp_customize->add_setting( 'simplistic_body_bg', array(
'default' => 'img/bright_squares.png'
));
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'simplistic_body_bg', array(
'label' => __( 'Upload a custom background image', 'simplistic' ),
'section' => 'simplistic_background',
'settings' => 'simplistic_body_bg',
) ) );
不确定在add\u控件
中是否有默认值
更新: 下面是我在主题中的一个例子,它是为一种颜色工作的:
$wp_customize->add_setting('wp27331869_navbar_background', array(
'default' => '#ffffff',
'transport' => 'postMessage'
));
$wp_customize->add_control(
new Pluto_Customize_Alpha_Color_Control(
$wp_customize,
'wp27331869_navbar_background',
array(
'label' => 'Header background',
'section' => 'nav',
'settings' => 'wp27331869_navbar_background',
'priority' => 15
)
)
);
在前端:
echo“背景:”。获取“主题”模块(“wp27331869”导航栏“背景”,“ffffff”)代码>
也许你可以试试,让它工作起来,然后根据你的需要调整它。你还没有为add\u setting()
添加第二个参数。谢谢你的回复。我尝试过修改后的代码,但不幸的是它并没有解决问题。它似乎根本没有输出默认数据。我认为add_settings
中的默认值仅适用于后端(自定义主题时默认选择)。如果您想要前端的默认值,请尝试使用以下命令:get_theme_mod('simplelistic_body_bg','img/bright_squares.png')代码>检查wp代码谢谢。我也尝试过,但这是一个正确的痛苦,不会输出默认数据grr。唯一有效的方法就是这样做:-用我在主题中使用的一个工作示例更新了我的第一个答案。