Forums

Taxonomy Menu (2 posts)

  1. stugoo
    Member
    Posted 1 year ago #

    Im using taxonomies to create a custom side navigation which has 2 levels.

    I was pulling out the entire list of taxonomies and using the nesting to create the relevant ordered lists.
    as follows :

    <?php
        $taxonomy     = 'work_categories';
        $orderby      = 'name';
        $show_count   = 0;
        $pad_counts   = 0;
        $hierarchical = 1;
        $title        = '';
    
        $args = array(
          'taxonomy'     => $taxonomy,
          'orderby'      => $orderby,
          'show_count'   => $show_count,
          'pad_counts'   => $pad_counts,
          'hierarchical' => $hierarchical,
          'title_li'     => $title,
          'exclude'		 => '28'
        );
    ?>
    
        <ul>
            <?php wp_list_categories( $args ); ?>
        </ul>

    which is outputting

    <ul>
        <li><a href=">Top level tax</a>
            <ul>
               <li><a href=">second level tax</a></li>
               <li><a href=">second level tax</a></li>
               <li><a href=">second level tax</a></li>
            </ul>
        </li>
    
        <li><a href=">Top level tax</a>
            <ul>
               <li><a href=">second level tax</a></li>
               <li><a href=">second level tax</a></li>
               <li><a href=">second level tax</a></li>
            </ul>
        </li>
    ...
    </ul>

    However I dont want the 1st level to be links. I have looked at doing a custom output using something like this :

    $terms = get_terms("work_categories");
    	 $count = count($terms);
    	 if ( $count > 0 ){
    		 echo "<ul>";
    		 foreach ( $terms as $term ) {
    		   echo "<li>" . $term->name . "</li>";
    
    		 }
    		 echo "</ul>";
    	 }
    	 echo "<pre>";
    	 print_r( $terms);
    	 echo "</pre>";

    But i found the logic to be really confusing...

    is there an easy way to achieve the following :

    <ul>
        <li>Top level tax  //NO LINK
            <ul>
               <li><a href=">second level tax</a></li>
               <li><a href=">second level tax</a></li>
               <li><a href=">second level tax</a></li>
            </ul>
        </li>
    
        <li>Top level tax //NO LINK
            <ul>
               <li><a href=">second level tax</a></li>
               <li><a href=">second level tax</a></li>
               <li><a href=">second level tax</a></li>
            </ul>
        </li>
    ...
    </ul>
  2. curtismchale
    Member
    Posted 1 year ago #

    I'd just use jQuery to find the :first-child li and remove the wrapping link. Probably not the cleanest but it would work.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.