Guest User

Untitled

a guest
Nov 21st, 2012
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  1. <?php      
  2. //# first of all, you need to get the category array,
  3. //   and I did it, putting the line bellow inside the loop
  4. $category = get_the_category(get_the_ID());
  5.  
  6. // once you have the category array, the rest of the code will work wherever you want on the page
  7.  
  8. //# getting the main category of the page
  9. $catid=$category[0]->category_parent;
  10. if($catid==0){
  11.   $catid=$category[0]->cat_ID;
  12. }
  13.  
  14. //# now letz get the children categories of the main category
  15. $categories = get_categories('child_of='.intval($catid));                    
  16.  
  17. foreach ($categories as $category) {
  18.     //# check if it is a real parent category with subcategories
  19.     if ($category->parent ==$catid):
  20.         echo
  21.         '
  22.         <div class="cat-item">
  23.         <div class="image">'.get_cat_icon("echo=false&cat=".$category->cat_ID).'</div>
  24.         <div class="text">
  25.         <a href="'.get_category_link($category->term_id ).'">'.$category->cat_name.'</a>
  26.         </div></div>
  27.         '
  28.        
  29.         ;
  30.         //# here we go, getting the subcategories
  31.         $subcategories=  get_categories('child_of='.intval($category->cat_ID));
  32.         foreach ($subcategories as $subcategory) {
  33.             echo '<span class="subcategory" style="padding-left:12px">';
  34.             echo '<a href="">'.$subcategory->cat_name.'</a></span>';
  35.         }
  36.        
  37.     endif;
  38. }
  39.  
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment