I am trying this thing:
<li>
<a href="#subcategory-slug">Subcategory Name</a>
</li>
and here is the code I am using:
<li>
<?php $displayed = array();?>
<?php $my_query = new WP_Query('category_name=Products&posts_per_page=9999');
while ($my_query->have_posts()) : $my_query->the_post();
?>
<a href="<?php foreach((get_the_category()) as $category ) { if($category->parent != 0) { echo '#'. $category->category_nicename . ' '; } } ?>">
<?php foreach((get_the_category()) as $category ) { if($category->parent != 0) { echo $category->cat_name . ' '; } } ?></a>
</li>
It kind of work only if there is just one post per subcategory, but if there are more then one post for the same category I get duplicate content:
<li>
<a href="#subcategory-slug">Subcategory Name</a>
</li>
<li>
<a href="#subcategory-slug">Subcategory Name</a>
</li>
<li>
<a href="#subcategory-slug">Subcategory Name</a>
</li>
So my question is how to alter the code so for multiple post to the same subcategory it displays just once that subcategory?