dongliechuich10319 2015-07-16 21:11
浏览 64
已采纳

do_settings_sections在WordPress管理员中无效

I am using the WordPress Settings API to build an options page for my theme. I can't get the input elements to display in the admin. I think I've narrowed the problem to the do_settings_sections(); function as it is the only thing not rendering anything on the front end.

    function cbc_theme_init() {
        register_setting( 'cbcsettings-group', 'carousel_options' );
        add_settings_section(
            'cbc_carousel_section',
            'Carousel Settings',
            'cbc_carousel_section_callback',
            'cbcsettings'
        );

        add_settings_field(
            'cbc_slide_one_title',
            'Title',
            'cbc_slide_title_callback',
            'cbcsettings',
            'cbc_carousel_section'
        );

    } // end cbc_theme_init

    function cbc_carousel_section_callback() {

    } // end cbc_carousel_section_callback

    function cbc_slide_title_callback() {

        $options = get_option( 'carousel_options' );

        /*if( !isset( $options[ 'slide_one_title' ] ) ) {
            $options[ 'slide_one_title' ] = '';
        }*/

        $html = '<input type="text" id="cbc_slide_one_title" name="carousel_options[slide_one_title]" value="' . $options[ 'slide_one_title' ] . '" />';
        $html .= '<lable for="cbc_slide_one_title">Title for first slide.</label>';

        echo $html;

    } // end cbc_slide_title_callback

    function cbc_add_theme_page() {

        add_theme_page(
            __( 'Theme Options', 'cbcsettings' ),
            __( 'Theme Options', 'cbcsettings' ),
            'edit_theme_options',
            'cbcsettings',
            'cbc_theme_options_page'
        );

     } // end cbc_add_theme_page
     add_action( 'admin_menu', 'cbc_add_theme_page' );

     function cbc_theme_options_page() {
    ?>

        <div class="wrap">
            <h2>Theme Options - <?php echo wp_get_theme(); ?></h2>
            <?php get_settings_errors(); ?>

            <form method="post" action="options.php">
                <?php 
                    settings_fields( 'cbcsettings-group' );
                    do_settings_sections( 'cbcsettings' );
                    submit_button(); 
                ?>
            </form>
        </div>
    <?php
     } // end cbc_theme_options_page
  • 写回答

1条回答 默认 最新

  • doucha7329 2015-07-21 15:21
    关注

    Finally figured it out! Apparently, I forgot to initiate my code. All I needed to do was call the following function add_filter( 'admin_init', 'cbc_theme_init' );

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用