$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>having a page in multi sub-menu and match current-menu-item|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

having a page in multi sub-menu and match current-menu-item

matteradmin23PV0评论

On a website I develop, some pages are in several sub-menus, like so:

home | product category a | products category b
       * product a          * product c
       * product b          * product b --> same as in previous menu

Now how do I get WordPress to add current-menu-item and current-menu-parent classes to "products category b" and "page b" instead of "product b" in the "product category a".

Currently, it seems that WordPress matches the entries in menu on a first encountered basis. So the entry in that appears first in the menu always takes precedence.

Instead I'd need WordPress to consider what was actually clicked.

So far, the easiest option I have found (no code changes required) is to add a parameter to the url to match a specific menu.

"page b" in "products category b" has its url appended with ?cat=b. This way, the url is unique to a menu and WP matches it right.

Nevertheless, it's not ideal for SEO and caching. I am therefore still looking for a better solution.

Post a comment

comment list (0)

  1. No comments so far