get_option issues

时间:2017-12-25 作者:GoldoKnack

你好,首先我为我糟糕的英语水平感到抱歉。

我正在寻找一些教程,从零开始使用wordpress上的自定义程序来创建主题。但我对get\\u选项有一些问题,我没有回报。我把我的密码写对了。

<?php
//==================================================
//============= Chargement des scripts =============
//==================================================

define(\'schweitzer_ver\', \'0.2\');


// Chargement front end
function schweitzer_scripts(){

    // Chargement des styles
    //wp_enqueue_style( \'styles-bootstrap\', get_template_directory_uri() . \'/css/bootstrap.min.css\',
    //  \'\', schweitzer_ver, \'all\' );
    wp_enqueue_style( \'styles\', get_template_directory_uri() . \'/style.css\',
        array(), schweitzer_ver, \'all\' );
    wp_enqueue_style( \'menu\', get_template_directory_uri() . \'/css/menu.css\',
        array(), schweitzer_ver, \'all\' );


    // Chargement des scripts
    wp_enqueue_script( \'schweitzer_script\', get_template_directory_uri() . \'/js/schweitzer.js\',
        array(\'jquery\'), schweitzer_ver, true );
    wp_enqueue_script( \'menu_script\', get_template_directory_uri() . \'/js/menu.js\',
        array(\'jquery\'), schweitzer_ver, true );
    }

    // Intégration et mise en forme du menu
    function clean_custom_menus() {
        $menu_name = \'primary\';
        if (($locations = get_nav_menu_locations()) && isset($locations[$menu_name])) {
            $menu = wp_get_nav_menu_object($locations[$menu_name]);
            $menu_items = wp_get_nav_menu_items($menu->term_id);
            // $menu_list = \'<nav>\' ."\\n";
            $menu_list .= "\\t\\t\\t\\t". \'<ul>\' ."\\n";

        foreach ((array) $menu_items as $key => $menu_item) {
            $title = $menu_item->title;
            $url = $menu_item->url;
            $menu_list .= "\\t\\t\\t\\t\\t". \'<li><a href="\'. $url .\'">\'. $title .\'</a></li>\' ."\\n";
            }

        $menu_list .= "\\t\\t\\t\\t". \'</ul>\' ."\\n";
        $menu_list .= "\\t\\t\\t". \'</nav>\' ."\\n";
        }

        else {
        $menu_list = \'Pas de menu défini\';
        }
    echo $menu_list;
}



add_action( \'wp_enqueue_scripts\', \'schweitzer_scripts\', \'clean_custom_menus\');


//==================================================
//================= Configuration ==================
//==================================================

function schweitzer_setup ()
{

    // Active gestion des menus (avec plusieurs positions)
    register_nav_menus(array(\'primary\'=>\'principal\'));

    // support des vignettes
    add_theme_support(\'post-thumbnails\');

    // Retire générateur de version (sécurité !)
    remove_action(\'wp_head\', \'wp_generator\');

    // Retire guillemets français
    remove_filter (\'the_content\', \'wptexturize\');

    // Support du titre géré par WP (meilleur SEO)
    add_theme_support(\'title-tag\');

}

    add_action( \'after_setup_theme\', \'schweitzer_setup\' );

//==================================================
//================ Options du theme ================
//==================================================

function schweitzer_customizer()
{

    //===== Variables =====
    // Couleur du menu
    $menu_color = get_option(\'menu_color\',\'#2a2a2a\');

    // Transparence du menu
    $menu_opacity = get_option(\'menu_opacity\',\'0.5\');

    // Nombre d\'éléments dans le menu
    // $menu_element = get_option( \'menu_element\' );

    ?>
    <style>
        nav li:nth-of-type(1){background-color: <?php echo $menu_color; ?>; opacity: <?php echo $menu_opacity; ?>}
        nav li:nth-of-type(2){background-color: <?php echo $menu_color; ?>; opacity: <?php echo $menu_opacity; ?>}
        nav li:nth-of-type(3){background-color: <?php echo $menu_color; ?>; opacity: <?php echo $menu_opacity; ?>}
        nav li:nth-of-type(4){background-color: <?php echo $menu_color; ?>; opacity: <?php echo $menu_opacity; ?>}
        nav li:nth-of-type(5){background-color: <?php echo $menu_color; ?>; opacity: <?php echo $menu_opacity; ?>}
    </style>
    <?php

}
    add_action( \'wp_head\', \'schweitzer_customizer\' );




function schweitzer_customize_register( $wp_customize ) {

        $wp_customize->add_section( \'menu_options\' , array(
        \'title\' =>  \'Réglage du Menu\',
    ) );

    $wp_customize->add_setting( \'menu_color\' , array(
        \'default\' => \'#000\',
        \'sanitize_callback\' => \'sanitize_hex_color\',
    ) );

    $wp_customize->add_setting( \'menu_opacity\' , array(
        \'default\' => \'0.5\',
    ) );

    $wp_customize->add_control(
        new WP_Customize_Color_Control($wp_customize,
            \'menu_color_selection\',
            array(\'label\' => \'Choix de la couleur\',
                \'section\' => \'menu_options\',
                \'settings\' => \'menu_color\',
        )
    ));

    $wp_customize->add_control(
        \'menu_opacity_selection\',
        array(
            \'label\'    => __( \'Transparence\', \'schweitzer\' ),
            \'section\'  => \'menu_options\',
            \'settings\' => \'menu_opacity\',
            \'type\'     => \'radio\',
            \'choices\'  => array(
                \'0\'  => \'0% (opaque)\',
                \'0.1\' => \'10 %\',
                \'0.2\'  => \'20 %\',
                \'0.3\' => \'30 %\',
                \'0.4\'  => \'40 %\',
                \'0.5\' => \'50 %\',
                \'0.6\'  => \'60 %\',
                \'0.7\' => \'70 %\',
                \'0.8\' => \'80 %\',
                \'0.9\'  => \'90 %\',
                \'1\' => \'100 % (transparent)\',),
        )
    );
}
add_action( \'customize_register\', \'schweitzer_customize_register\' );

function schweitzer_register_settings() {
    register_setting( \'menu_settings\', \'my_option_name\', \'intval\' );
}

add_action( \'admin_init\', \'schweitzer_register_settings\' );
这是我的职能。php。后端似乎工作正常,但没有我的痕迹“menu_color“options.Wp\\u head位于index.php中。

如果你能帮忙,我将非常感谢。

1 个回复
SO网友:GoldoKnack

我在另一个论坛上找到了解决方案,但如果有人遇到了与我相同的问题,以下是解决方案:

对于通过$wp_customize修改的主题选项,请使用get_theme_mod()而不是get_option()来检索值。

结束

相关推荐

Why does it loop twice?

我有这个循环,我不知道为什么,我有一个“加载更多”按钮,当我点击它时,它会再次加载所有文章。有人能帮忙吗?<div class=\"content\"> <div class=\"container load_more\"> <div class=\"row\"> <?php $args = array(\'category_name\' => \'actu, quizz\' );