Support » Themes and Templates » help with adding ID to wp_list_pages()

  • Resolved po3


    Hi, I’m trying to create dynamic menu highlighting to a theme I’m working with. Right now the following code generates the navigation:

    			<li<?php if (is_home()) { echo " id=\"current\"";}?>><a href="<?php echo get_settings('home'); ?>">Home</a></li>
    			<?php wp_list_pages('title_li=&depth=1'); ?>

    As you can see I was able to add dynamic menu highlighting to the homepage link, but how would I add this too the rest of the dynamically generated page links? Can I add something to “wp_list_pages(‘title_li=&depth=1’)” in order to add the id=”current” to the currently selected page?

    Thanks in advance. I’m new to wordpress and just figuring our my way around…

Viewing 3 replies - 1 through 3 (of 3 total)
  • WordPress insert a current-page-item automatically on the page that’s being viewed.

    Edit: so it would be better to give the homepage a current_page_item class as well (instead of current)

    walterego, I’m totally lost. Can you explain further?

    Well, it’s really quite simple. Every item in a list that’s generated by wp_list_pages looks has a couple of css classes applied. an item looks like this:
    <li class="page_item page_item-11"><a href="http://domain.tld/page-name/"></li>

    page_item-11 means that the page’s ID is 11. The page you are currently viewing looks like this in the list:
    <li class="page_item page_item-11 current_page_item"><a href="http://domain.tld/page-name/"></li>

    This way you can highlight the page in the pages list when it’s being viewed. To imake things easier for you change id=”current” to class=”current_page_item”. You can then create style rules for the different classes in you theme’s stylesheet.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘help with adding ID to wp_list_pages()’ is closed to new replies.