Taxonomy Navigation – Accordion Functionality
-
Thanks to vtxyzzy and wprelief I’ve managed to get a sidebar navigation going based off of Taxonomy Terms and their posts as sub lists. The code is as follows:
<ul id="port_nav"> <?php $terms = get_terms('typeofproject'); foreach ($terms as $term) { $wpq = array ('taxonomy'=>'typeofproject','term'=>$term->slug); $myquery = new WP_Query ($wpq); $article_count = $myquery->post_count; echo "<li class=\"term-heading\" id=\"".$term->slug."\">"; echo "<a href=\"#".$term->slug."\">".$term->name."</a>"; echo "</li>"; echo "<li style='padding: 0;' class=''>"; if ($article_count) { echo "<ul>"; while ($myquery->have_posts()) : $myquery->the_post(); echo "<li>> <a href=\"".get_permalink()."\">".$post->post_title."</a></li>"; endwhile; echo "</ul>"; } echo "</li>"; } ?> </ul>
The only part I have left to achieve is hiding the posts of terms that don’t relate to the current page. You can see an end (static) example of how it should look here:
https://skitch.com/whipd/dmcjw/portfolio-navigation.psd-100-group-2-rgb-8Doing an If Statement that using CSS to hide the irrelevant posts seems easy enough but as mentioned in the previous post the trouble is determining which term page you are currently on.
To add to the troubles there’s a core bug in the system that prevents you using is_tax(‘something’). Please see the ticket here. I’m not sure what that means but a friend passed me on to it. It may be fixed by now?
- The topic ‘Taxonomy Navigation – Accordion Functionality’ is closed to new replies.