Options.php loop won't show!

时间:2013-06-28 作者:Connor

我正在为存储在选项中的本地主机上的主题创建选项面板。php文件。我的选项面板将有两个主回路。第一个是列出不同的部分,第二个将创建这些部分。我刚刚编写了第一个循环,它在运行时不会显示任何内容。此循环和一些周围html的代码是:

<aside>
    <nav>
        <ul>
        <?php
        foreach ($options as $value){
            switch ( $value[\'type\'] ){
                case \'section\':
                    echo \'<li><a>\'.$value[\'name\'].\'</li></a>\';
                    break;
            }
        }
        ?>
        </ul>
    </nav>
</aside>
不过我看不出这有什么错。这让我相信,我的代码的不同部分出了问题,下面是所有选项。php文件:

<?php

//theme vars
$themename = "Fuckin Round";
$shortname = "fuckinround";
$options = array();

function theme_options(){
    global $themename, $shortname, $options;

    $options = array (

        array("name" => "General Settings",
            "type" => "section"),
        array("type" => "open"),

        array("name" => "Type of Logo",
            "desc" => "Select your logo type ( Image or Text )",
            "id" => $shortname."_type_of_logo",
            "type" => "select",
            "options" => array("text", "logo"),
            "std" => "text"),

        array("name" => "Logo Upload",
            "desc" => "Upload images using the native media uploader, or define the URL directly",
            "id" => $shortname."_logo_upload",
            "type" => "imageupload",
            "std" => ""),

        array("name" => "Logo Text",
            "desc" => "Enter text for logo",
            "id" => $shortname."_logo_text",
            "type" => "text",
            "std" => ""),

        array("name" => "Logo Slogan",
            "desc" => "Enter text for logo slogan",
            "id" => $shortname."_logo_slogan",
            "type" => "text",
            "std" => ""),

        array("name" => "Custom Favicon",
            "desc" => "Upload a 16px x 16px Png/Gif image that will represent your website\'s favicon",
            "id" => $shortname."_favicon_upload",
            "type" => "imageupload",
            "std" => ""),

        array("type" => "close"),
        array("name" => "Styling Options",
            "type" => "section"),
        array("type" => "open"),

        array("name" => "Background Color",
            "desc" => "Pick a color for the background",
            "id" => $shortname."_background_color",
            "type" => "color",
            "std" => "#ffffff"),

        array("name" => "Body Color",
            "desc" => "Pick a color for the body",
            "id" => $shortname."_body_color",
            "type" => "color",
            "std" => "#ffffff"),

        array("type" => "close"),
        array("name" => "Footer Options",
            "type" => "section"),
        array("type" => "open"),

        array("name" => "Copyright Text",
            "desc" => "Enter text for copyright in footer (if empty it will be removed)",
            "id" => $shortname."_footer_text",
            "type" => "text",
            "std" => "Copyright TestSite.com"),

        array("type" => "close")

    );
}

//add options page
function fuckinround_add_admin(){
    global $themename, $shortname, $options;

    if ( $_GET[\'page\'] == basename(__FILE__) ){

        if ( \'save\' == $_REQUEST[\'action\'] ) {
            //protect against request forgery
            check_admin_referer(\'theme-save\');

            //save the options
            foreach ($options as $value) {
                if( isset( $_REQUEST[ $value[\'id\'] ] ) ) {
                    update_option( $value[\'id\'], $_REQUEST[ $value[\'id\'] ] );
                } else {
                    delete_option( $value[\'id\'] );
                }
            }

            header("Location: themes.php?page=options.php&saved=true");
            die;

        } else if ( \'reset\' == $_REQUEST[\'action\'] ) {
            //protect against request forgery
            check_admin_referer(\'theme-reset\');
            //delete the options
            foreach ($option as $value) {
                delete_option( $value[\'id\'] );
            }

            header("Location: themes.php?page=options.php&reset=true");
            die;
        }
    }
    add_theme_page($themename." Options", "$themename Options", \'edit_themes\', basename(__FILE__), \'fuckinround_admin\');
}
add_action(\'admin_menu\' , \'fuckinround_add_admin\');

//main function
function fuckinround_admin() {
    global $themename, $shortname, $options;

    //saved or reset messages
    if ( $_REQUEST[\'saved\'] ) echo \'<div id="message" class="updated fade"><p><strong>\'.$themename.\' settings saved.</strong></p></div>\';
    if ( $_REQUEST[\'reset\'] ) echo \'<div id="message" class="updated fade"><p><strong>\'.$themename.\' settings reset.</strong></p></div>\';

    //form
    ?>
    <header>
        <h1><?php echo $themename; ?></h1>
    </header>

    <aside>
        <nav>
            <ul>
            <?php
            foreach ($options as $value){
                switch ( $value[\'type\'] ){
                    case \'section\':
                        echo \'<li><a>\'.$value[\'name\'].\'</li></a>\';
                        break;
                }
            }
            ?>
            </ul>
        </nav>
    </aside>

    <main>
    <?php
        //loop 2
    ?>
    </main>

    <footer>

        <form method="post">
            <?php wp_nonce_field(\'theme-save\'); ?>
            <p class="submit">
                <input name="save" type="submit" value="Save changes" class="button-primary" />
                <input type="hidden" name="action" value="save" />
            </p>
        </form>

        <form method="post">
            <?php wp_nonce_field(\'theme-reset\'); ?>
            <p class="submit">
                <input name="reset" type="submit" value="Reset changes" />
                <input type="hidden" name="action" value="reset" />
            </p>
        </form>
    </footer>
    <?php
}
?>
我已多次阅读此代码,但找不到任何可能导致循环无法正常工作的内容。如果你们能看看并告诉我你们有什么发现,我会非常感激的。提前谢谢。抱歉主题名称不成熟。

1 个回复
最合适的回答,由SO网友:vancoder 整理而成

我看不到你的theme_options 在任何位置调用函数。

结束

相关推荐

如何将php的等价物添加到一个页面(作为插件?)

我是Wordpress的新手。我有一个自己编写的网站。其中一个页面具有PHP函数,可以获取google日历提要(带有硬编码的登录信息)并根据需要显示它。我现在正在wordpress上建立一个新站点,在那里我想使用相同的代码。我的阅读表明,我应该将其作为创建新插件来处理,这样我就不会用任何主题更新来覆盖它。我的问题是:如何简单地将PHP代码复制到它自己的插件文件夹中的一个文件中,然后使用一个快捷码像include一样访问它?具体地说,我不明白我是否能够使用shortcode作为<php? includ