gpt4 book ai didi

php - wordpress 定制器默认设置不起作用

转载 作者:行者123 更新时间:2023-11-28 07:32:01 28 4
gpt4 key购买 nike

我正在为 wordpress 开发我的第一个主题,但遇到了一些问题。我正忙于为主题构建定制页面。在定制器不会将默认设置解析为 css 之前,一切都很好。我尝试重新构建函数文件,但没有任何效果。

你们能不能看一下代码并告诉我是否有什么问题,或者如果其他人有这个问题,请告诉我解决方案是什么。

这是我的 funtions.php 文件的代码

<?php

add_theme_support( 'menus' );
if ( function_exists( 'register_nav_menus' ) ) {
register_nav_menus(
array(
'header-menu' => 'main'
)
);
}
add_action( 'init', 'register_my_menus' );

add_theme_support( 'post-thumbnails' );

function claboxico_customize_register( $wp_customize ) {


//fonts array
$googlefonts = array(
'arial'=>'Arial',
'verdana'=>'Verdana, Geneva',
'trebuchet'=>'Trebuchet',
'trebuchet ms'=>'Trebuchet MS',
//this list contains way more fonts
);

//general panel
$wp_customize->add_panel( 'colors', array(
'title' => __( 'Colors' ),
'description' => 'Edit the general styling',
) );

//general colors section
$wp_customize->add_section('primairy_color', array(
'title' => __('Primairy Colors', 'claboxico'),
'panel' => 'colors',
'description' => 'Edit the primairy color of the theme.'
));
//primairy color setting
$wp_customize->add_setting('primairy_color', array(
'default' => '#43bfd8',
));
//primairy color control
$wp_customize->add_control( new WP_Customize_Color_control( $wp_customize, 'primairy_color', array(
'label' => __('Primairy Color', 'claboxico'),
'section' => 'primairy_color',
'setting' => 'primairy_color',
) ));


//link kleur
$wp_customize->add_section('link_color', array(
'title' => __('Link Colors', 'claboxico'),
'panel' => 'colors',
'description' => 'Edit the color of the links.'
));
$wp_customize->add_setting('link_color', array(
'default' => '#0eb1ed',
));
$wp_customize->add_control( new WP_Customize_Color_control( $wp_customize, 'link_color', array(
'label' => __('Link Color', 'claboxico'),
'section' => 'link_color',
'setting' => 'link_color',
) ));

//plain text color
$wp_customize->add_section('paragraph_color', array(
'title' => __('Paragraph Colors', 'claboxico'),
'panel' => 'colors',
'description' => 'Edit the paragraph text color.'
));
$wp_customize->add_setting('paragraph_color', array(
'default' => '#000',
));
$wp_customize->add_control( new WP_Customize_Color_control( $wp_customize, 'paragraph_color', array(
'label' => __('Link Color', 'claboxico'),
'section' => 'paragraph_color',
'setting' => 'paragraph_color',
) ));




//fonts panel
$wp_customize->add_panel( 'fonts', array(
'title' => __( 'Fonts' ),
'description' => 'Edit the fonts',
) );

//heading fonts section
$wp_customize->add_section('heading_font', array(
'title' => __('Heading fonts', 'claboxico'),
'panel' => 'fonts',
'description' => 'Edit the font for h1, h2 etc.'
));
$wp_customize->add_setting('heading_font', array(
'default' => 'Rokkitt',
));

$wp_customize->add_control( 'heading_font',array(
'type' => 'select',
'label' => __('Heading font', 'claboxico'),
'section' => 'heading_font',
'setting' => '',
'choices' => $googlefonts,
)
);



}

function claboxico_css_customizer() {
?>

<style type="text/css">

@import url(http://fonts.googleapis.com/css?family=<?php
$font_sizes = ':300,400,700,900|';
$heading_google_font = get_theme_mod('heading_font');
$heading_font = str_replace(' ', '+', $heading_google_font);
echo $heading_font;
echo $font_sizes;

$paragraph_google_font = get_theme_mod('paragraph_font');
$paragraph_font = str_replace(' ', '+', $paragraph_google_font);
echo $paragraph_font;
echo $font_sizes;


?>);
body{font-family: '<?php echo get_theme_mod('paragraph_font'); ?>'; color: <?php echo get_theme_mod('paragraph_color'); ?> }
/* background color */
.header{background-color: <?php echo get_theme_mod('header_background_color'); ?> ;}
/* heading colors and font */
h1, h2, h3, header .logo{color: <?php echo get_theme_mod('primairy_color', '#43bfd8');?> ; font-family:'<?php echo get_theme_mod('heading_font'); ?>';}
/*link colors*/
a, a:hover{color: <?php echo get_theme_mod('link_color');?>;}
/* primairy colors */
header{border-bottom-color: <?php echo get_theme_mod('primairy_color', '#43bfd8');?> ;}
header .mobile-header-icon, header nav ul li a{color: <?php echo get_theme_mod('primairy_color', '#43bfd8');?> ;}

footer{border-top-color: <?php echo get_theme_mod('primairy_color', '#43bfd8');?> ;}

</style>

<?php
}
add_action('wp_head', 'claboxico_css_customizer');
add_action( 'customize_register', 'claboxico_customize_register' );
?>

我希望有人能帮我解决这个问题。

最佳答案

函数 get_theme_mod 可以接受两个参数。

  • $name(必填)= 设置名称
  • $default(可选)= 如果数据库中没有设置值,则为默认值

检查法典页面:https://codex.wordpress.org/Function_Reference/get_theme_mod

示例:

$color = get_theme_mod( 'link_color', '#ff0000' );

在此示例中,默认值 #ff0000 被传递。如果设置了值,则将返回保存的值,否则 $color 将获得默认值 #ff0000

关于php - wordpress 定制器默认设置不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31452674/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com