$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'); ?>php - Dynamic Menu drops pages?|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)

php - Dynamic Menu drops pages?

matteradmin11PV0评论

I've created a Dynamic Menu that highlights the selected page and colors for example the blog page "red" while the other links (home, about, contanct) remain white.

My question is how can I make the Dynamic Menu work when say the blog goes to /blog/page/2/ and have the blog remain red instead of dropping the highlight?

Here's the code for my menu.


< nav id="menu" class="mid" role="navigation">
  < ?php wp_nav_menu( array( 'theme_location' => 'primary-menu' ) ); ?>
< /nav>

Then, I register the menu inside the functions.php


add_action( 'init', 'register_my_menu' );
    function register_my_menu() {
        register_nav_menu( 'primary-menu', __( 'Primary Menu' ) );
    }

Here's the CSS that highlights the .current-menu-item

#menu .current-menu-item a { opacity: 1.0; }

This is when the Menu is Active on example/work

This is when the Menu is Active on the example/blog *just the first blog page though

This is the menu when it switches to example/blog/page/2, example/work/showcase/website1337

How, can I make it so that the Dynamic Menu detects that /page/2 is still associated with the parent page "/blog/, /work/" and is still highlighted like images 1 and 2?

Thanks :3

I've created a Dynamic Menu that highlights the selected page and colors for example the blog page "red" while the other links (home, about, contanct) remain white.

My question is how can I make the Dynamic Menu work when say the blog goes to /blog/page/2/ and have the blog remain red instead of dropping the highlight?

Here's the code for my menu.


< nav id="menu" class="mid" role="navigation">
  < ?php wp_nav_menu( array( 'theme_location' => 'primary-menu' ) ); ?>
< /nav>

Then, I register the menu inside the functions.php


add_action( 'init', 'register_my_menu' );
    function register_my_menu() {
        register_nav_menu( 'primary-menu', __( 'Primary Menu' ) );
    }

Here's the CSS that highlights the .current-menu-item

#menu .current-menu-item a { opacity: 1.0; }

This is when the Menu is Active on example/work

This is when the Menu is Active on the example/blog *just the first blog page though

This is the menu when it switches to example/blog/page/2, example/work/showcase/website1337

How, can I make it so that the Dynamic Menu detects that /page/2 is still associated with the parent page "/blog/, /work/" and is still highlighted like images 1 and 2?

Thanks :3

Share Improve this question edited Jan 11, 2019 at 20:56 Glorfindel 6113 gold badges10 silver badges18 bronze badges asked Feb 6, 2013 at 23:22 Monstr92Monstr92 1371 silver badge10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Test:

#menu current_page_ancestor a { opacity: 1.0; }

Check this Menu Item CSS Classes

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far