• Anyone know how to specify ids for links in the navigation bar that are generated through wp_list_pages and list_categories. I want to do this so I can make them highlight on the nav bar when that page is current as per the example at https://codex.www.ads-software.com/Dynamic_Menu_Highlighting.

    Also can you tell me where exactly to put (where in the header.php?) the conditional statement?
    <?php
    if ( is_page(‘Page One’) ) { $current = ‘one’; }
    elseif ( is_page(‘Page Two’) ) { $current = ‘two’; }
    elseif ( is_page(‘Page Three’) ) { $current = ‘three’; }
    elseif ( is_page(‘Page Four’) ) { $current = ‘four’; }
    ?>

    THANKS in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • For Pages you don’t really need that script/code. The wp_list_pages has an output that wraps every list item in a “page_item” class + puts a “current_page_item” additional class for the Page that is displayed. (Check your source) You just have to define those classes in your CSS.

    Thread Starter hkenna

    (@hkenna)

    Hi Moshu,

    Thanks for replying, but I am afraid, I don’t understand your answer, please excuse my technical stupidity. I was trying to follow the example in the codex for dynamic menu highlighting – do you know a different way to do this? the problem I am having is how and where do you specify what page is current so a style can be applied to that link on the sidebar navigation.
    I am truly lost with this one. But thanks for replying anyway. H.

    See here:
    https://codex.www.ads-software.com/Template_Tags/wp_list_pages

    When wp_list_pages is called while displaying a Page, the list item for that Page will be given the additional CSS class “current_page_item”.

    Any metohd to do the same with categories ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘ids for pages and categories’ is closed to new replies.