How to display in WordPress Category, Category post, Subcategory, Subcategory post?

How to display in WordPress Category, Category post, Subcategory, Subcategory post?
First you need to click on image and check how will result show on your page.
And is this useful to you



simple Copy and paste this code on your index page or where ever you want to show.
Only you need to change the categories id in the array
Hope this will help you
<?php
                            $row = 0;
// Here you can pass the id of your category which you want to show
                            $arrayid = array('0'=>9,'1'=>10,'2'=>7,'3'=>8,'4'=>11,'5'=>12);
                            foreach($arrayid as $aid)
                            {
                            if($row%3==0){ ?> <div class="row-fluid"> <?php }
                            ?>
                                <div class="span4 box-featured">
                                    <div class="bf-title">
                                            <div class="prod-menu">
                                         
                                            <ul class="nav">
                                            <li class="dropdown">
                                            <a href="#" data-description="For Employees" class="btn dropdown-toggle"><span class="icons-bf-dropdown"></span></a>
                                            <ul class="dropdown-menu productsmenu">
                                         
                                            <?php
// Here will show Main category post if sub category has any post
                                            query_posts(array('category__in' => array($aid)));
                                         
                                            while(have_posts()) { the_post();
                                            ?>
                                         
                                         
                                            <?php $screen = get_post_meta($post->ID, 'screen', $single = true); ?>
                                            <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
                                            </li>
                                         
                                            <?php } ?>
                                         
                                            <?php
                                            //Reset Query
                                            wp_reset_query(); ?>
                                         
                                         
<?php
// Here will show Subcategory category if main category has any Subcategory
                                                    $categories =  get_categories('child_of='.$aid);
                                                    foreach  ($categories as $category) {
                                                    //Display the sub category information using $category values like $category->cat_name
                                                    ?>
                                                    <li><a href="<?php echo get_category_link($category->term_id);?>"><?=$category->name?></a>
                                                        <ul class="dropdown-menu productsmenu">
                                                     
<?php
// Here will show sub category post if sub category has any post
                                                            query_posts(array('category__in' => array($category->term_id)));
                                                         
                                                            while(have_posts()) { the_post();
                                                            ?>
                                                         
                                                         
                                                            <?php $screen = get_post_meta($post->ID, 'screen', $single = true); ?>
                                                            <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
                                                            </li>
                                                         
                                                            <?php }
wp_reset_query();
?>
                                                        </ul>
                                                    </li>
                                                    <?php } ?>
                                            </ul>
                                            </li></ul>
                                            </div>
                                    <?php
// Get main category Details
$yourcat = get_category($aid); ?>
                                    <div class="prod-title">
                                    <h4><?=$yourcat->name?></h4>
                                    </div>
                                    </div>
                                    <div class="bf-images">
                                    <?php if (function_exists('z_taxonomy_image_url')) {
?><img alt="<?=$yourcat->name?>" src="<?php echo z_taxonomy_image_url($aid);?>">
<?php
}else
{ ?>
<img alt="<?=$yourcat->name?>" src="<?php echo get_template_directory_uri(); ?>/images/product2.jpg">
<?php }
?>
                                 
                                    </div>
                                    <div class="bf-content">      
                                    <p>
                                    <?php echo $yourcat->description;?>
                                 
                                    </p>
                                    </div>
                                 
                                    <div class="bf-readmore">
                                    <span>
                                    <a href="<?php echo get_category_link($aid);?>">Read More</a>
                                    </span>
                                    </div>
                                </div>
                            <?php $row++; if($row%3==0){ ?> </div> <?php }
                            } ?>

Comments