2
votes

I'm wondering how to show just only subcategories on a parent category?

Is there any way to do this?

I'm using this code.

<?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');
    echo '<ul>' . $new_cats . '</ul>';
   }
}
?>

I have parent category videos and 3 child categories of that art,technology and funny.

Now I just want to show only 3 child categories in category:videos

But my problem is that there is also showing parent category posts. And when I go to any of child category page, there is show this line No categories on the category title. For example, when I go to art category page, then on the category title of Art this line is shown.

Please suggest me complete and useful solution.

UPDATED

Here is my entire category.php template:

<?php get_header(); ?>

<article class="content">
<div id="marquee-container"><div  title="News Updates…" alt="News Updates…"  style="position:relative;  background-color: #FFF; width:137px; height:19px; z-index:1; border-radius:3px; background-image:url(<?php bloginfo('template_directory'); ?>/images/wp0465f11b_06.png); display:inline-block;"></div><h4 class="marquee-text">New Features Coming Soon...</h4></div>

    <?php if ( have_posts() ) : ?>
        <div class="posts">
            <h1 class="archive-title"><?php printf( __( 'Category: %s', 'OnlinEarn' ), single_cat_title( '', false ) ); ?></h1>

            <?php if ( category_description() ) : // Show an optional category description ?>
            <div class="archive-meta"><?php echo category_description(); ?></div>
            <?php endif; ?>
        <?php $args = array('child_of' => 'videos'); ?>
            <?php
            if (is_category('videos'))
            {
            $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');

               }
            }
        ?>


        <?php /* The loop */ ?>

            <?php while ( have_posts() ) : the_post(); ?>

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

            <?php endwhile; ?>


        </div><!--.posts-->


    <?php else : ?>
        <?php get_template_part( 'content', 'none' ); ?>
    <?php endif; ?>

    </article><!-- .content -->
1
Will someone answer my question?? I m highly suffered from it.user2579060

1 Answers

1
votes
<?php get_header(); ?>

<article class="content">
<div id="marquee-container"><div  title="News Updates…" alt="News Updates…"  style="position:relative;  background-color: #FFF; width:137px; height:19px; z-index:1; border-radius:3px; background-image:url(<?php bloginfo('template_directory'); ?>/images/wp0465f11b_06.png); display:inline-block;"></div><h4 class="marquee-text">New Features Coming Soon...</h4></div>

    <?php if ( have_posts() ) : ?>
        <div class="posts">
            <h1 class="archive-title"><?php printf( __( 'Category: %s', 'OnlinEarn' ), single_cat_title( '', false ) ); ?></h1>

            <?php if ( category_description() ) : // Show an optional category description ?>
            <div class="archive-meta"><?php echo category_description(); ?></div>
            <?php endif; endif;

            $category = get_the_category();

            if ($category[0]->category_parent != '' && is_category('video')) :

             //show child categories
            $cur_cat = get_query_var('cat');

                $new_cats = wp_list_categories('echo=false&child_of=' . $cur_cat  .'&depth=1&title_li=&&show_count=1&hide_empty=0');
                echo '<ul>' . $new_cats . '</ul>';

            elseif ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

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

            <?php endwhile; ?>


        </div><!--.posts-->


    <?php else : ?>
        <?php get_template_part( 'content', 'none' ); ?>
    <?php endif; ?>

    </article><!-- .content -->