我正在为存储在选项中的本地主机上的主题创建选项面板。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
}
?>
我已多次阅读此代码,但找不到任何可能导致循环无法正常工作的内容。如果你们能看看并告诉我你们有什么发现,我会非常感激的。提前谢谢。抱歉主题名称不成熟。