【问题标题】:Create options menu in WordPress在 WordPress 中创建选项菜单
【发布时间】:2013-12-10 15:15:37
【问题描述】:

我有一些代码可以在 WordPress 中创建一个“选项”菜单,来自 here。我正在使用文档中的示例,但我不确定如何使它起作用。理想情况下,我想使用用户在主题其他地方的管理表单中输入的值,例如:

<?php echo_the_twitter_link(); ?>

这是当前代码:

<?php
/*
Plugin Name: Admin Menu
Plugin URI: x
Description: x
Author: x
Author URI: x
*/

// create custom plugin settings menu
add_action('admin_menu', 'baw_create_menu');

function baw_create_menu() {

    //create new top-level menu
    add_menu_page('BAW Plugin Settings', 'BAW Settings', 'administrator', __FILE__, 'baw_settings_page');

    //call register settings function
    add_action( 'admin_init', 'register_mysettings' );
}


function register_mysettings() {
    //register our settings
    register_setting( 'baw-settings-group', 'new_option_name' );
    register_setting( 'baw-settings-group', 'some_other_option' );
    register_setting( 'baw-settings-group', 'option_etc' );
}

function baw_settings_page() {
?>
<div class="wrap">
<h2>Social Media Links</h2>

<form method="post" action="options.php">
    <?php settings_fields( 'baw-settings-group' ); ?>
    <table class="form-table">
        <tr valign="top">
        <th scope="row">New Option Name</th>
        <td><input type="text" name="new_option_name" value="<?php echo get_option('new_option_name'); ?>" /></td>
        </tr>

        <tr valign="top">
        <th scope="row">Some Other Option</th>
        <td><input type="text" name="some_other_option" value="<?php echo get_option('some_other_option'); ?>" /></td>
        </tr>

        <tr valign="top">
        <th scope="row">Options, Etc.</th>
        <td><input type="text" name="option_etc" value="<?php echo get_option('option_etc'); ?>" /></td>
        </tr>
    </table>

    <p class="submit">
    <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
    </p>

</form>
</div>
<?php } ?>

【问题讨论】:

    标签: php wordpress wordpress-theming


    【解决方案1】:

    要在主题中的任何位置使用 WordPress 选项,只需像这样调用选项名称:

    echo get_option('some_other_option');
    

    我希望这会有所帮助,并且是您需要的?

    【讨论】:

      猜你喜欢
      • 2016-02-07
      • 2021-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-19
      • 1970-01-01
      相关资源
      最近更新 更多