WordPress.org

Ready to get started?Download WordPress

Forums

Set active class in a Php foeach (1 post)

  1. Archie22is
    Member
    Posted 1 year ago #

    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>

Topic Closed

This topic has been closed to new replies.

About this Topic