Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //# first of all, you need to get the category array,
- // and I did it, putting the line bellow inside the loop
- $category = get_the_category(get_the_ID());
- // once you have the category array, the rest of the code will work wherever you want on the page
- //# getting the main category of the page
- $catid=$category[0]->category_parent;
- if($catid==0){
- $catid=$category[0]->cat_ID;
- }
- //# now letz get the children categories of the main category
- $categories = get_categories('child_of='.intval($catid));
- foreach ($categories as $category) {
- //# check if it is a real parent category with subcategories
- if ($category->parent ==$catid):
- echo
- '
- <div class="cat-item">
- <div class="image">'.get_cat_icon("echo=false&cat=".$category->cat_ID).'</div>
- <div class="text">
- <a href="'.get_category_link($category->term_id ).'">'.$category->cat_name.'</a>
- </div></div>
- '
- ;
- //# here we go, getting the subcategories
- $subcategories= get_categories('child_of='.intval($category->cat_ID));
- foreach ($subcategories as $subcategory) {
- echo '<span class="subcategory" style="padding-left:12px">';
- echo '<a href="">'.$subcategory->cat_name.'</a></span>';
- }
- endif;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment