質問

Ok, I know that there are several other questions on SO regarding this topic. By now, I have probably read all of them. I have been researching this for a little over two hours now and I am coming to the end of the road (about to give up!)... So, here I am on SO finally asking the question to involve other sharp minds.

I am helping build this Wordpress site: greatman.us. And, the Posts page is located on a page called "Blog." The "active" menu item is highlighting properly on PAGES, but when you go to a POST, the "Blog" menu item is not longer highlighted (i.e. NOTHING is highlighted in the header menu).

There is no way in Wordpress - as far as I'm aware - to create a "parent" for a blog post. This option is only available for Pages. I need to be able to have the "Blog" menu item stay highlighted when I am viewing a BLOG POST.

For a general example:

mywebsite.com/blog/ <--- menu item "Blog" is highlighted

mywebsite.com/blog/post223 <--- menu item "Blog" is no longer highlighted

I am proficient with CSS and HTML, but not with PHP. So, if this is a PHP fix, please dumb your answer down as much as possible.

I have read tons of other articles about this online and it seems to be a common issue, with most people not knowing how to code with PHP.

I am using a custom theme, called Divi. And it is missing some of the CSS elements that other forums and sites I have read said that the style.css should have. This is another reason I am coming to a dead end. Please help!

By the way, one WORKAROUND I discovered is to add POSTS as sub-menu items to the "Blog" page that you made in the Wordpress Menus area (in the admin back-end). Then, use "display:none" is CSS to remove the submenu from being displayed to the public. This causes two main problems, though: 1) You can never have any other sub-menu items, because they won't be displayed. 2) You have to manually add every single blog post to the menu as a sub-menu item. This will eventually make your menu super long assuming you are a regular blogger. It is also a hassle.

役に立ちましたか?

解決

Within your CSS, you will also need to add .current-page-ancestor with the same attribtues as your current menu item.

Something similar to below:

.current_page_item, .current-page-ancestor {
    // Some attributes
}

This is guessing that you have use wp_nav_menu() though. If not then I'll need to see what code you have used to generate the menus.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top