开发者

Add "On" state to wordpress menu

I have this code that generates a WP menu:

              <div id="menu">
  <?php $args = array(
    'depth'        => 1,
    'show_date'    => '',
    'date_format'  => get_option('date_format'),
    'child_of'     => 0,
    'exclude'      => '426, 508',
    'include'      => '',
    'title_li'     => __(''),
    'echo'         => 1,
    'authors'      => '',
    'sort_column'  => 'menu_order, post_title',
    'link_before'  => '',
    'link_after'   => '',
    'walker' => '' ); ?>
    <ul><div class="menu-button"><?php wp_list_pages( $args, 'sort_column=menu_order' ); ?></div></ul>
    </di开发者_运维百科v>

I have some CSS to to the hover states of the menu items but is it possible to show an "on" state so if the user is on that actual page, the menu item is a different color?


When wp_list_pages() is called while displaying a Page, the list item for that Page is given the additional class current_page_item.

Source: codex.wordpress.org/Function_Reference/wp_list_pages#Markup_and_styling_of_page_items

So if you set a CSS rule for .current_page_item, you can style the current page's list style in your navigation.


I'm not too clued up on wordpress but hopefully their codex shall cover it all http://codex.wordpress.org/Function_Reference/wp_nav_menu. Is it a must that the menu is generated dynamically or could you hard code it?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜