I have custom taxonomy "oferta" and custom post type "produkt".
An "oferta" is needed to create categories and subcategories for posts in "produkt".
I have a lot of categories and subcategories and I need to show pages according to the scheme:
- First I see main categories only
- When I choose one I see subcategories which belongs only to that category I choosed.
- Next I can choose another subcategory and so on.
- And on the last page I see list of posts which belongs to that particular subcategory only.
In addition, I need to hide subcategories that do not have posts.
In taxonomy-oferta.php I have code:
<section id="primary" class="site-content">
<div id="content" role="main">
<header class="entry-header">
<h1 class="entry-title"><?php single_cat_title(); ?></h1>
</header>
<?php
$term = get_queried_object();
$term_id = $term->term_id;
$taxonomy_name = $term->taxonomy;
$termchildren = get_term_children( $term_id, $taxonomy_name );
echo '<ul>';
foreach ( $termchildren as $child ) {
$term = get_term_by( 'id', $child, $taxonomy_name );
echo '<li><a href="' . get_term_link( $term, $taxonomy_name ) . '">' . $term->name . '</a></li>';
}
echo '</ul>'; ?>
<?php if ( have_posts() ) : ?>
<?php
while ( have_posts() ) : the_post();
get_template_part( 'content', 'oferta' );
endwhile;
twentytwelve_content_nav( 'nav-below' );
?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div>
</section>
Effect is that I see everyting at once:
- Main categories
- Subcategories
- And below are all posts
When I click on subcategory I see all the sub-subcategories of that one and below all the posts from sub- and sub-subcategories.
Can anyone help me with this code to get the effect I described at the beginning?