因此,我遵循了这篇帖子的公认答案Possible to add another setting to 'Front page displays' setting for Custom Post Type
但并不完全有效,必须与本帖中公认的答案进行比较。
Can't output do_settings_sections . Can't understand why
现在,它实际上使用以下代码工作
//Add settings to menu
add_action( \'admin_menu\', \'events_options_add_page\' );
function events_options_add_page() {
// add_submenu_page(\'edit.php?post_type=events\', \'Events Admin\', \'Events Settings\', \'edit_posts\', basename(__FILE__), \'events_options_do_page\');
add_submenu_page(\'edit.php?post_type=events\', \'Events Admin\', \'Events Settings\', \'edit_posts\', basename(__FILE__), \'events_options_do_page\');
}
//https://wordpress.stackexchange.com/questions/32689/possible-to-add-another-setting-to-front-page-displays-setting-for-custom-post
//Fix Cap to allow editors to edit theme options
function events_get_options_page_cap() {
return \'edit_posts\';
}
add_filter(\'option_page_capability_events-options\', \'events_get_options_page_cap\' );
function events_options_do_page() {
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2><?php _e( \'Events Options\', \'FoundationPress\' ); ?></h2>
<form action="options.php" method="post">
<?php
settings_fields( "events_settings_options" );
do_settings_sections( "edit_posts" );
?>
<?php submit_button( __( "Save changes", "FoundationPress" ), "primary", "submit", true ); ?>
</form>
</div>
<?php
}
//Register Settings
add_action( \'admin_init\', \'events_settings_register\' );
function events_settings_register() {
register_setting( "events_settings_options", "events_settings_options", "events_settings_validate" ); //Register main settings
// add_settings_section( "events_cpt_settings", __( "Events Page Settings", "FoundationPress" ), "events_settings_dummy", "edit_posts" ); //Make settings text section
// add_settings_field( "events_settings_cpt_page", __( "Page for events", "FoundationPress" ), "events_settings_page_select", "edit_posts", "events_settings_options" );
add_settings_section( "events_cpt_settings", __( "Events Page Settings", "FoundationPress" ), "events_settings_dummy", "edit_posts" ); //Make settings text section
add_settings_field( "events_settings_cpt_page", __( "Page for events", "FoundationPress" ), "events_settings_page_select", "edit_posts", "events_cpt_settings" );
}
function events_settings_dummy() {}
//Validate Settings
function events_settings_validate ($input) {
$valid = get_option ( "events_settings_options" );
$valid[\'events_page\'] = (int) $input[\'events_page\'];
return $valid;
}
//Settings Fields
function events_settings_page_select() {
$options = get_option( \'events_settings_options\' );
wp_dropdown_pages(
array(
\'name\' => \'events_settings_options[events_page]\',
\'echo\' => 1,
\'show_option_none\' => __( \'— Select —\' ),
\'option_none_value\' => \'0\',
\'selected\' => $options[\'events_page\']
)
);
}
为了让它发挥作用,我注意到这两个示例之间的差异,并将do\\u settings\\u部分更改为edit\\u posts。。。现在在我看来,它的目的是为了获得权限或功能,我已经尝试了其他一些技巧,但只是在wordpress中找到了你没有权限等。
谁能帮我理解一下我的代码吗?我已经绕了一圈,非常希望能有另一双眼睛看着它。
在此之后,我需要将其设置为页面实际工作方式与在阅读页面中设置页面一样,以便加载我的自定义帖子类型存档。
非常感谢各位!
编辑:
不得不颠簸,迫切需要一些帮助!很高兴在paypal上喝杯啤酒!