如何将子菜单页面添加到自定义帖子类型?

时间:2012-08-22 作者:zoaCode

我试图在我命名为公文包的自定义帖子类型下创建一个子菜单。

当我改变时add_submenu_page()add_options_page(), 它在设置菜单下正确显示一个新链接,但在公文包菜单下不显示。

我做错了什么?

下面是我的代码片段;

add_action( \'admin_menu\', \'mt_add_pages\' );

function mt_add_pages() {
    add_submenu_page(
        __( \'portfolios\', \'menu-test\' ),
        __( \'Test Settings\', \'menu-test\' ),
        \'manage_options\',
        \'testsettings\',
        \'mt_settings_page\'
    );

    function mt_settings_page() {
        echo "<h2>" . __( \'Test Settings\', \'menu-test\' ) . "</h2>";
    }
}

4 个回复
SO网友:NightHawk

add_options_page() 但是,会自动将其添加到设置下面add_submenu_page() 让您可以控制它显示在哪里。

尝试以下操作:

add_submenu_page(
    \'edit.php?post_type=portfolios\',
    __( \'Test Settings\', \'menu-test\' ),
    __( \'Test Settings\', \'menu-test\' ),
    \'manage_options\',
    \'testsettings\',
    \'mt_settings_page\'
);

SO网友:Artistan

要扩展@Jai示例。。。

我的设置

$postType = \'foo\';
$categoryType = \'bar\';
自定义帖子类型
            $args = array(
                    \'labels\'             => array(\'name\'=>$postType, ...),
                    \'rewrite\'            => array(\'slug\' => \'all-\'.$postType),
                    \'taxonomies\'         => array($categoryType)
            );

register_post_type( \'foo\', $args );
自定义类别分类法
            $args = array(
                    \'labels\'            => array( \'name\' => _x( $categoryType, \'taxonomy general name\' )),
                    \'rewrite\'           => array( \'slug\' => $categoryType ),
            );

register_taxonomy( $categoryType, array( $postType ), $args );
将类别添加为子菜单项
    $wp_term = get_categories( \'taxonomy=\'.$categoryType.\'&type=\'.$postType ); 
    if ( $wp_term ) {
        foreach ( $wp_term as $term ) {
            // add_submenu_page( string $parent_slug, string $page_title, string $menu_title, string $capability, string $menu_slug,                                                  callable $function = \'\' )
            add_submenu_page(    \'edit.php?post_type=\'.$postType,      $term->name,        $term->name,        \'manage_options\',   \'edit.php?post_type=\'.$postType.\'&\'.$categoryType.\'=\'.$term->slug, \'\'); 
        }
    } 

SO网友:Jai

add_submenu_page(\'edit.php?post_type=\'.$this->plugin->posttype, __(\'Settings\', $this->plugin->name), __(\'Settings\', $this->plugin->name), \'manage_options\', $this->plugin->name, array(&$this, \'adminPanel\'));
有一个管理面板是一个回调函数名。

SO网友:Lincoln Lemos

/**
* Adds a submenu page under a custom post type parent.
*/
function books_register_ref_page() {
    add_submenu_page(
        \'edit.php?post_type=book\',
        __( \'Books Shortcode Reference\', \'textdomain\' ),
        __( \'Shortcode Reference\', \'textdomain\' ),
        \'manage_options\',
        \'books-shortcode-ref\',
        \'books_ref_page_callback\'
    );
}

/**
* Display callback for the submenu page.
*/
function books_ref_page_callback() { 
    ?>
    <div class="wrap">
        <h1><?php _e( \'Books Shortcode Reference\', \'textdomain\' ); ?></h1>
        <p><?php _e( \'Helpful stuff here\', \'textdomain\' ); ?></p>
    </div>
    <?php
}
Link to Source , 作者:Christina Blust

结束

相关推荐