WordPress.org

Support

Support » How-To and Troubleshooting » Set active class in a Php foeach

Set active class in a Php foeach

  • Archie22is

    @archie22is

    I have the following code to display a list of taxonomies in WordPress. It works and my only concern is the active class (li class=”active”). Err, how do I go about making it dynamic?

    <ul id="filter">
            <?php
            echo '<li class="active"><a href="#" class="all">All</a></li>'; # this remains static and unchanged
                if ( $count > 0 ) {
                    foreach ( $mylinks as $mylink ) {
                        echo '<li>';
                        # get current webdirectory and link to taxonomy menus
                        echo'<a href=' . network_site_url() . '/services/' .$mylink->slug . ' class='. $mylink->slug .'" >';
                        echo $mylink->name;
                        echo "</a>";
                        echo "</li>";
                    }
                }
            ?>
        </ul>
  • The topic ‘Set active class in a Php foeach’ is closed to new replies.
Skip to toolbar