WordPress.org

Ready to get started?Download WordPress

Forums

Selected Menu in WordPress dynamic menu (1 post)

  1. Archie22is
    Member
    Posted 1 year ago #

    Hi guys,

    I am using the following code to generate menu from the WordPress categories. The menu is dynamic based on the built created categories.

    <ul class="menu clearfix">
    	<?php
    		# Navigation Taxonomy Menu ---> so dynamic it's unbelievable!
    		$mylinks = get_terms('category', array(
    			'parent' => 0,				# display parent category links only
    			'orderby' => 'name',
    			'hide_empty' => 0
    			)
    		);
    		$count = count($mylinks);
    
    		if ( $count > 0 ) {				# From the above, we create a menu
    			foreach ( $mylinks as $mylink ) {
    				echo '<li class="page_item">';
    				# get current webdirectory and link to taxonomy menus
    				echo '<a href=' . network_site_url() . '/' . $mylink->slug . ' class="'. $mylink->slug .'" >';
    				echo $mylink->name;
    				echo "</a>";
    				echo "</li>";
    				}
    			}
    	?>
    </ul>

    The thing however is, although the menu works fine, I cannot set active/selected menus.

    Err, how will I go about doing that? Say add a class to an active or selected menu?

Topic Closed

This topic has been closed to new replies.

About this Topic