Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I just want to show only subcategories of specific parent category on parent category page. I have 1 parent category videos and 3 child categories art,funny,and technology of that parent.

I didn't assigned my parent videos category to my child categories, but I made them child of that videos parent cateogry.

and I don't want to show parent categories on parent category page and neither want to show any category when go to any post related of child category page.

How to do this? any idea?

I am using this code. And I used this code into my category.php file.

   <?php
            if (is_category())
            {
            $cur_cat = get_query_var('cat');
            if ($cur_cat) 
               {
                $new_cats = wp_list_categories('echo=false&child_of=' . $cur_cat  .'&depth=1&title_li=&&show_count=1&hide_empty=0');

               }
            }
        ?>

But this is not working desired as I want.

I also tried 1 more solution for that,I made another template called content-videos.php and I call that template with

   <?php if ( in_category('videos')):?>
        <?php get_template_part( 'content', 'videos' ); ?>
        <?php else:?>
            <?php while ( have_posts() ) : the_post(); ?>

                <div class="block"><?php get_template_part( 'content', get_post_format()    ); ?></div>

            <?php endwhile; ?>

            <?php endif;?>

in my category.php template. and I put my 1st code into content-videos.php.that solved my 1st problem, but my next problem was that when I go to in any subcategory page there is noting show except No categories

please suggest me any solution of this I am suffered too much to finding the right solution what I want.

share|improve this question
    
That's just how categories work. If I have a box labelled junk, and inside it there's a box called 'blue junk', then the junk box contains all the blue junk too. Categories and hierarchical taxonomies work the same way. –  Tom J Nowell Jan 29 at 14:45
    
Is this the answer of my question? –  Mr.beginner Jan 29 at 14:48
    
It's useful information, I'm not entirely sure what form your desired result would take, be it a list of child categories, or showing posts that are only in the current term and no others, the latter of which would have complexity issues –  Tom J Nowell Jan 29 at 14:51
    
well its not my answer, I want complete answer with solution. –  Mr.beginner Jan 29 at 15:14
    
I think my point is, it isn't clear what a complete answer would give you, can you edit your question to be clearer about what you're trying to achieve? What is the expected output? –  Tom J Nowell Jan 29 at 15:37
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.