Forums

[resolved] Give home-link a current item-class (4 posts)

  1. wp_pia
    Member
    Posted 1 year ago #

    Hello :-)

    I have created a menu below my header like this:

    <div id="menu1">

    • ">Home
    • <?php wp_list_categories('orderby=ID&title_li='); ?>

    </div>

    My question is: How do I give the Home-link a current-item-class? It works fine on the other links, but Home-link is not marked, when I´m on the Home-page.

    I will be very grateful for any help and suggestions. Thanks in advance.

  2. wp_pia
    Member
    Posted 1 year ago #

    Sorry I´m new. I will try to post my code again:

    <div id="menu1">
    <ul>
     <li><a href="<?php echo get_settings('home'); ?>">Forside</a></li>
    <?php wp_list_categories('orderby=ID&title_li=');  ?>
    
    </ul>
    </div>
  3. alchymyth
    The Sweeper
    Posted 1 year ago #

    this might work:

    <div id="menu1">
    <ul>
    
    <li <?php if ( is_front_page() ) { echo ' class="current-cat"'; } ?>><a href="<?php echo get_settings('home'); ?>">Forside</a></li>
    <?php wp_list_categories('orderby=ID&title_li=');  ?>
    
    </ul>
    </div>

    alternatively try is_home() instead of is_front_page()

  4. wp_pia
    Member
    Posted 1 year ago #

    Thank you very much. It worked right away:-)

Topic Closed

This topic has been closed to new replies.

About this Topic