是否在HTML中拆分DO_SETTINGS_SECTIONS?

时间:2015-10-20 作者:user82238

这看起来应该很容易实现,但我花了太长时间试图弄明白。我有两个设置部分:

add_settings_section( \'cp_required_info\', \'One\', array($this, \'cp_required_info\'), \'cp-settings\' );
add_settings_section( \'cp_sync_info\', \'Two\', array($this, \'cp_sync_info\'), \'cp-settings\' );
register_setting( \'cp-settings\', \'cp_admin_options\', array( $this, \'sanitize\' ) );
如何将这些部分输出到HTML中的不同位置?do\\u settings\\u sections仅允许$页。我尝试了do\\u settings\\u字段,该字段允许使用$page和$section,它确实达到了我想要的效果,但是当我删除do\\u settings\\u部分并只保留do\\u settings\\u字段时,我的所有输出都会消失。下面是我努力实现的一个例子。

<?php settings_fields( \'cp-settings\' );   
//do_settings_sections( \'cp-settings\' );
do_settings_fields( \'cp-settings\', \'cp_required_info\' );?>

<!--Some HTML goes here-->

<?php
do_settings_fields( \'cp-settings\', \'cp_sync_info\' );?>
?>
有人知道如何做到这一点吗?我所有的回调都正常工作,只需将部分放在页面上即可。

编辑:包括add\\u settings\\u字段:

public function cp_required_info() {
        add_settings_field( \'cp_apikey\', \'API Key:\', array( $this, \'cp_apikey_callback\' ), \'cp-settings\', \'cp_required_info\', array( \'label_for\' => \'cp_apikey\') );      
        add_settings_field( \'cp_username\', \'Username:\', array( $this, \'cp_username_callback\' ), \'cp-settings\', \'cp_required_info\', array( \'label_for\' => \'cp_username\') );      
        add_settings_field( \'cp_tablename\', \'Table Name:\', array( $this, \'cp_tablename_callback\' ), \'cp-settings\', \'cp_required_info\', array( \'label_for\' => \'cp_tablename\') );      
    }

public function cp_sync_info() {
        add_settings_field(\'cp_collect_posts\', \'Posts\', array($this, \'cp_posts_callback\'), \'cp-settings\', \'cp_sync_info\', array( \'label_for\' => \'cp_collect_posts\') );
    }

1 个回复
SO网友:T Andrew

算了,算了吧。进行了以下更改:

add_settings_section( \'cp_required_info\', null, array($this, \'cp_required_info\'), \'cp-settings-group\' );
add_settings_section( \'cp_sync_info\', null, array($this, \'cp_sync_info\'), \'cp-settings-group\' );
register_setting( \'cp-settings-group\', \'cp_admin_options\', array( $this, \'sanitize\' ) );
<小时>
<?php settings_fields( \'cp-settings-group\' );   
do_settings_sections( \'cp-settings-group\' );
do_settings_fields( \'cp-settings\', \'cp_required_info\' );?>

<!--Some HTML goes here-->

<?php
do_settings_fields( \'cp-settings\', \'cp_sync_info\' );?>
?>

相关推荐