Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WordPress创建设置页面_Php_Wordpress - Fatal编程技术网

Php WordPress创建设置页面

Php WordPress创建设置页面,php,wordpress,Php,Wordpress,我正在尝试学习如何在WordPress中定制仪表板页面和设置。我遵循的教程非常清楚…但是有一件很小的事情对我来说没有意义 在demo\u footer\u message\u display()。我不明白“信息”的定义在哪里。如果它说选项['footer\u message'],那就很有意义了,因为'footer\u message'是我正在处理的字段的id 代码运行良好,但我不明白为什么?其中“message”曾经定义为选项数组的索引。谁能给我解释一下吗 顺便说一句,我的设置页面只是有一个输入

我正在尝试学习如何在WordPress中定制仪表板页面和设置。我遵循的教程非常清楚…但是有一件很小的事情对我来说没有意义

demo\u footer\u message\u display()。我不明白“信息”的定义在哪里。如果它说选项['footer\u message'],那就很有意义了,因为'footer\u message'是我正在处理的字段的id

代码运行良好,但我不明白为什么?其中“message”曾经定义为选项数组的索引。谁能给我解释一下吗

顺便说一句,我的设置页面只是有一个输入,你可以在主题的页脚输入一些文本

functions.php

演示主题选项
| 
如果您查看方法get\u选项之前的单词(array),它表明他正在将返回作为数组进行强制转换(这篇文章说)。设置api还说get\u选项的返回类型为“混合”。我猜表单是在发布选项页面上呈现的文本字段,它将文章中的所有内容保存到数据库中,当您检索它时,将其转换为数组以检索文章的“消息”部分会更容易。尝试取消播放它,并使用“var_dump”查看它返回的内容,看看您是否能找到比我更好的答案:)


谢谢,好建议。var_dump的结果($options);是:在输入字段中输入单词tests后,数组(1){[“message”]=>string(5)“tests”}。我仍然不确定“消息”是从哪里来的……我猜它是WordPress的get_options()函数的一部分??我只是没有看到任何说明这一点的文档。请尝试访问wordpress后端的“选项”页面,并在文本字段所在的表单上使用inspect元素。如果与页脚消息相对应的输入字段有一个包含单词message的数组,则您将知道是否已设置该字段。如果它不在那里,那么它可能意味着它是由表单创建的post操作的“消息”。。。希望这有意义。嗯,好的。因此,我替换了代码中所有显示“message”的地方,并将它们改为test,我的代码仍然有效。所以我发现wordpress并没有定义这一点,我想当你开始制作$message=$options['message']语句…您将“message”作为选项数组中的键引入…然后该键的值由输入值定义。感谢您帮助我查看此内容。感谢您实际尝试了解其工作原理:)
<?php
/* --------------------------------------------*
 * Menus
/*---------------------------------------------*/

// Adds the 'DEMO THEME OPTIONS' to the 'Settings' menu in WordPress

function demo_add_options_page(){
    add_options_page(
            'Lindsay Demo Theme Options', //browser title
            'Lindsay Demo Theme Options', // menu text
            'manage_options',  // required capability of users to access this menu
            'lindsay-demo-theme-options', // slug
            'demo_theme_option_display' // name of function used to display content
        );
} 
add_action('admin_menu', 'demo_add_options_page');

/* --------------------------------------------*
 * Sections, Settings, and Fields
/*---------------------------------------------*/

// Registers a new settings field on the 'Demo Theme Options' page

function demo_initialize_theme_options(){

    //section to be rendered on the new options page
    add_settings_section(
        'footer_section', //id 
        'Footer Options', //title on screen
        'demo_footer_options_display', //callback 
        'lindsay-demo-theme-options'//ID of page 
        );

    //define the settings field
    add_settings_field(
        'footer_message', //ID of field
        'Theme Footer Message', //label
        'demo_footer_message_display', //callback 
        'lindsay-demo-theme-options', // page 
        'footer_section' // the section to add to
        );

    //Register the 'footer_message' setting with the 'General' section
        register_setting(
            'footer_section', //name of the group of settings
            'footer_options' //name of option
            );
} //end demo_initialize_theme_options

add_action('admin_init', 'demo_initialize_theme_options');

/* --------------------------------------------*
 * Callbacks
/*---------------------------------------------*/

function demo_theme_option_display(){
?>
    <div class="wrap">
        <h2 >Demo Theme Options</h2>
        <form method="post" action="options.php">
            <?php
                // render the settings for the settings section identified as 'Footer section'
                settings_fields('footer_section');

                //render all of the settings for 'demo-theme-options' sections
                do_settings_sections('lindsay-demo-theme-options');

                // add the submit button to serialize options
                submit_button();
            ?>
        </form>
    </div>
<?php
}

function demo_footer_message_display(){
$options = (array)get_option('footer_options');
$message = $options['message'];
echo '<input type="text" name="footer_options[message]" id="footer_options_message" value="'.$message.'"/>';
}

function demo_footer_options_display(){
echo 'These options are designed to help you control whats dislayed in your footer';
}
<div id="footer" class="col-md-12"> 
<?php wp_footer() ?>
        <div class="site-info">
            <a href="http://wordpress.org/" title="A Semantic Personal Publishing Platform" rel="generator">Proudly Powered by WordPress</a>
            <span class="sep"> | </span>
            <?php $options = (array) get_option('footer_options');?>
            <?php $message = $options['message'];?>
            <span id="footer-message"><?php echo $message; ?></span>
        </div>
</div>
$options = get_option('footer_options');
var_dump($options)