小编Net*_*ket的帖子

WordPress 导航菜单未显示在自定义存档页面上

我目前正在创建 WordPress 主题,并偶然发现了一个我不完全理解的问题。我使用以下方法在位置上显示我的导航菜单mega_menu

wp_nav_menu(array('theme_location' => 'mega_menu'));
Run Code Online (Sandbox Code Playgroud)

这适用于所有正常的帖子和页面。但是,当我位于自定义帖子类型的存档页面上时,menschen菜单不会显示。var_dumping 位置上的导航菜单mega_menu确实返回 WP_Term 对象,但获取项目返回空数组。我不明白这种奇怪的行为,希望有人能帮助我。

我尝试在文件中显示菜单header.phpget_header()在存档页面上调用。

这是我的自定义帖子类型的注册:

function thg_custom_post_type()
{
    register_post_type(
        'menschen',
         array(
            'labels'      => array(
                'name'          => __('Menschen'),
                'singular_name' => __('Mensch'),
            ),
            'public'            => true,
            'has_archive'       => true,
            'show_in_rest'      => true,
            'taxonomies'        => array( 'category' ),
            'menu_icon'         => 'dashicons-businesswoman',
            'supports'          => array( 'title', 'editor', 'thumbnail', 'excerpt', 'custom-fields' ),
            'rewrite'           => array( 'slug' => 'menschen' ),
        )
    );
}

add_action('init', 'thg_custom_post_type');

Run Code Online (Sandbox Code Playgroud)

php wordpress wordpress-theming

2
推荐指数
1
解决办法
810
查看次数

标签 统计

php ×1

wordpress ×1

wordpress-theming ×1