Answer the question
In order to leave comments, you need to log in
Why doesn't WordPress see sequence in pages?
Good afternoon!
It didn’t work out for me to briefly formulate the question in the subject, so I’ll analyze it in detail here.
The problem is the following.
Let's say we have page navigation. Posts are displayed on the "blog" page, and the engine marks this page in the menu as active (current). If we go deeper into the post, then it loses its logical connection with the parent page ("blog").
What's most interesting is that "breadcrumbs" keep track of everything normally.
Tell me, please, how to fix this?
Answer the question
In order to leave comments, you need to log in
1. Breadcrumbs are arbitrary code, not a native WP function/feature, it was apparently originally made with this in mind. 2. WordPress keeps track of the current page
in the menu . The Blog page is not current if you are on a single post page. The current page is, oddly enough, the page of this post, but it is not in the menu. That is, there is nothing to fix there - WP does exactly what it should do, and exactly the way it should be done. However, if you want to highlight the parent menu item (in this case, "Blog" if you're on blog-related pages), this can be done with a filter:
function add_custom_class( $classes=array(), $menu_item=false ) {
if ( ! is_page() && 'Blog' == $menu_item->title && ! in_array( 'current-menu-item', $classes ) ) {
$classes[] = 'current-menu-item';
}
return $classes;
}
add_filter( 'nav_menu_css_class', 'add_custom_class', 100, 2 );
Добрый.
Страница "Блог" выбрана в Настройках как "Страница записей"? По идеи, при переходе на страницу записи пункту "Блог" должен присваиваться класс "current_page_parent". Для этого класса можно присвоить стили аналогично классу "current-menu-item".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question