WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] help with adding ID to wp_list_pages() (4 posts)

  1. po3
    Member
    Posted 6 years ago #

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

    <ul>
    			<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'); ?>
    
    		</ul>

    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...

  2. walterego
    Member
    Posted 6 years ago #

    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)

  3. po3
    Member
    Posted 6 years ago #

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

  4. walterego
    Member
    Posted 6 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic