我正在使用Twenty Sixteen主题并创建一个新的帖子类型。
function twentysixteen_setup() {
$labels = array(
'name' => __( 'News'),
'singular_name' => __( 'News'),
'menu_name' => __( 'News'),
'add_new' => __('Add News')
);
$args = array(
'labels' => $labels,
'description' => __( 'Description.'),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'news' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt')
);
register_post_type( 'news', $args );
}
add_action( 'after_setup_theme', 'twentysixteen_setup' );
我还创建了名为News的页面。点击新闻页面,显示新闻列表。但它没有显示Active
答案 0 :(得分:0)
更新设置中的固定链接并尝试。它会正常工作。
注意:强>
刚刚更新。无需更改任何固定链接类型。它会正常工作。
.RProfile
答案 1 :(得分:0)
我在function.php文件中创建了一个函数并在服务器上传。它对我来说很好。
function sid_custom_menu_classes($menu)
{
global $post;
if (get_post_type($post) == 'news')
{
$menu = str_replace( 'current-menu-item', '', $menu ); // remove all current_page_parent classes
$menu = str_replace( 'menu-item-77', 'menu-item-77 current-menu-item', $menu ); // add the current_page_parent class to the page you want
}
return $menu;
}
add_filter( 'nav_menu_css_class', 'sid_custom_menu_classes', 10,2 );