2016-12-16 2 views
0

Я использую тему 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.On Нажмите на странице новостей, где отображается список новостей. Но он не показывает Active

ответ

0

Я создал функцию в файле functions.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); 
0

обновите свою позицию в настройках и попробуйте. Он будет работать нормально.

Примечание:

Просто обновление. не нужно менять какой-либо постполяционный тип. Он будет работать нормально.

 add_action('init', 'codex_book_init'); 
     /** 
     * Register a book post type. 
     * 
     * @link http://codex.wordpress.org/Function_Reference/register_post_type 
     */ 
     function codex_book_init() { 
      $labels = array(
       'name'    => _x('news', 'post type general name', 'your-plugin-textdomain'), 
       'singular_name'  => _x('news', 'post type singular name', 'your-plugin-textdomain'), 
       'menu_name'   => _x('news', 'admin menu', 'your-plugin-textdomain'), 
       'name_admin_bar'  => _x('news', 'add new on admin bar', 'your-plugin-textdomain'), 
       'add_new'   => _x('Add New', 'news', 'your-plugin-textdomain'), 

      ); 

      $args = array(
       'labels'    => $labels, 
         'description'  => __('Description.', 'your-plugin-textdomain'), 
       'public'    => true, 
       'publicly_queryable' => true, 
       'show_ui'   => true, 
       'show_in_menu'  => true, 
       'query_var'   => true, 
       'rewrite'   => array('slug' => 'news'), 
       'capability_type' => 'post', 
       'has_archive'  => true, 
       'hierarchical'  => false, 
       'menu_position'  => null, 
       'supports'   => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments') 
      ); 

      register_post_type('news', $args); 
     } 
+0

Не могли бы вы рассказать о своем – Sudhir

+0

. перейдите к настройкам в меню и permalink – vel

+0

, а затем нажмите кнопку «Сохранить изменения» – vel

Смежные вопросы