是否有向21选项页面添加其他选项的功能?

时间:2011-07-08 作者:Gregg

我想通过子主题向Twentyeleven选项页添加其他选项,如页脚文本。我知道如何创建主题选项页,但如果可能的话,我想使用“二十一”附带的主题选项页。如果没有,我如何才能取消此选项页的挂钩并创建自己的选项页?

1 个回复
SO网友:Chip Bennett

你可以,但目前这并不容易。您必须重写现有代码,然后重新编写它以使用其他选项对其进行扩展。

从这里开始:

add_action( \'admin_menu\', \'twentyeleven_theme_options_add_page\' );
您需要删除此操作(在您的子主题中):

remove_action( \'admin_menu\', \'twentyeleven_theme_options_add_page\' );
然后,您需要复制twentyeleven_theme_options_add_page() 子主题中的函数:

function twentyeleven_child_theme_options_add_page() {
    $theme_page = add_theme_page(
        __( \'Theme Options\', \'twentyeleven\' ), // Name of page
        __( \'Theme Options\', \'twentyeleven\' ), // Label in menu
        \'edit_theme_options\',                  // Capability required
        \'theme_options\',                       // Menu slug, used to uniquely identify the page
        \'twentyeleven_child_theme_options_render_page\'            // Function that renders the options page
    );

    if ( ! $theme_page )
        return;

    $help = \'<p>\' . __( \'Some themes provide customization options that are grouped together on a Theme Options screen. If you change themes, options may change or disappear, as they are theme-specific. Your current theme, Twenty Eleven, provides the following Theme Options:\', \'twentyeleven\' ) . \'</p>\' .
            \'<ol>\' .
                \'<li>\' . __( \'<strong>Color Scheme</strong>: You can choose a color palette of "Light" (light background with dark text) or "Dark" (dark background with light text) for your site.\', \'twentyeleven\' ) . \'</li>\' .
                \'<li>\' . __( \'<strong>Link Color</strong>: You can choose the color used for text links on your site. You can enter the HTML color or hex code, or you can choose visually by clicking the "Select a Color" button to pick from a color wheel.\', \'twentyeleven\' ) . \'</li>\' .
                \'<li>\' . __( \'<strong>Default Layout</strong>: You can choose if you want your site&#8217;s default layout to have a sidebar on the left, the right, or not at all.\', \'twentyeleven\' ) . \'</li>\' .
            \'</ol>\' .
            \'<p>\' . __( \'Remember to click "Save Changes" to save any changes you have made to the theme options.\', \'twentyeleven\' ) . \'</p>\' .
            \'<p><strong>\' . __( \'For more information:\', \'twentyeleven\' ) . \'</strong></p>\' .
            \'<p>\' . __( \'<a href="http://codex.wordpress.org/Appearance_Theme_Options_Screen" target="_blank">Documentation on Theme Options</a>\', \'twentyeleven\' ) . \'</p>\' .
            \'<p>\' . __( \'<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>\', \'twentyeleven\' ) . \'</p>\';

    add_contextual_help( $theme_page, $help );
}
add_action( \'admin_menu\', \'twentyeleven_child_theme_options_add_page\' );
然后,您需要复制theme_options_render_page() 在儿童主题中的功能(例如twentyeleven_child_theme_options_render_page()), 添加其他主题选项。

请注意,希望在2011年的未来版本中,这将变得更加容易。我正准备提交一个补丁来转换它theme_options_render_page() 要使用的函数add_settings_section()add_settings_field() 调用,而不是硬编码的表标记。

结束

相关推荐