Support » Fixing WordPress » Set active class in a Php foeach

  • 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">
            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>";
  • The topic ‘Set active class in a Php foeach’ is closed to new replies.