gpt4 book ai didi

javascript - WordPress 主题选项错误

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

我正在按照本教程为 WordPress 主题制作自定义主题选项页面:http://theme.fm/2011/08/using-the-color-picker-in-your-wordpress-theme-options-2152/

一切都很好,直到我添加了颜色选择器功能和脚本。现在,每次我进入主题选项页面时,它都只是一个空白屏幕,并显示来自 Firebug 的错误。如这张图所示。

/image/bR4P2.png

我删除了颜色选择器的内容,但它仍在执行。我对 javascript 和 php 相当陌生,所以我不知道这里发生了什么。

这是我的主题选项页面的代码。

function mb_options_admin_menu() {
$page = add_theme_page( 'Theme Options', 'Theme Options', 'edit_theme_options', 'mb_options-theme-options', 'mb_options_theme_options' );
add_action( 'admin_print_styles-' . $page, 'mb_options_admin_scripts' );
}
add_action( 'admin_menu', 'mb_options_admin_menu' );

function mb_options_admin_scripts() {
// We'll put some javascript & css here later
}

function mb_options_theme_options() {
?>
<div class="wrap">
<div id="icon-themes" class="icon32" ><br></div>
<h2>My Theme Options</h2>

<form method="post" action="options.php">
<?php wp_nonce_field( 'update-options' ); ?>
<?php settings_fields( 'mb_options-theme-options' ); ?>
<?php do_settings_sections( 'mb_options-theme-options' ); ?>
<p class="submit">
<input name="Submit" type="submit" class="button-primary" value="Save Changes" />
</p >
</form>
</div>
<?php
}

function mb_options_admin_init() {
register_setting( 'mb_options-theme-options', 'mb_options-theme-options' );
add_settings_section( 'section_general', 'General Settings', 'mb_options_section_general', 'mb_options-theme-options' );
add_settings_field( 'link_color', 'Link Color', 'mb_options_setting_color', 'mb_options-theme-options', 'section_general' );
add_settings_field( 'link_hover_color', 'Link Hover Color', 'mb_options_hover_setting_color', 'mb_options-theme-options', 'section_general' );
}
add_action( 'admin_init', 'mb_options_admin_init' );

function mb_options_section_general() {
_e( 'The general section description goes here.' );
}

function mb_options_setting_color() {
$options = get_option( 'mb_options-theme-options' );
?>
<input type="text" name="mb_options-theme-options[link_color]" value="<?php echo esc_attr( $options['link_color'] ); ?>" />
<?php
}

function mb_options_hover_setting_color() {
$options = get_option( 'mb_options-theme-options' );
?>
<input type="text" name="mb_options-theme-options[link_hover_color]" value="<?php echo esc_attr( $options['link_hover_color'] ); ?>" />
<?php
}

function mb_options_link_color() {
$options = get_option( 'mb_options-theme-options' );
$link_color = $options['link_color'];
$link_hover_color = $options['link_hover_color'];
echo "<style> a { color: $link_color; } a:hover { color: $link_hover_color; } </style>";
}
add_action( 'wp_enqueue_scripts', 'mb_options_link_color' );

谁能告诉我这里出了什么问题以及解决方法吗?

最佳答案

看来错误是由于我使用的前缀造成的。已解决。

关于javascript - WordPress 主题选项错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36245639/

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