Advertisement
alchymyth

cat archive general idea

Nov 21st, 2012
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php      
  2. //# getting the main category of the page
  3. $catid = get_query_var('cat');
  4. $cat = get_category( $catid );
  5.  
  6. //#check if this is top-level cat//
  7. if( !$cat->parent ) : //there is no parent cat, therefore this is the top cat//
  8.  
  9. //# now letz get the children categories of the main category
  10. $categories = get_categories('child_of='.intval($catid));                    
  11.  
  12. foreach ($categories as $category) {
  13.     //# check if it is a real parent category with subcategories
  14.     if ($category->parent == $catid):
  15.         echo
  16.         '
  17.         <div class="cat-item">
  18.         <div class="image">'.get_cat_icon("echo=false&cat=".$category->cat_ID).'</div>
  19.         <div class="text">
  20.         <a href="'.get_category_link($category->term_id ).'">'.$category->cat_name.'</a>
  21.         </div></div>
  22.         '
  23.        
  24.         ;
  25.         //# here we go, getting the subcategories
  26.         $subcategories=  get_categories('child_of='.intval($category->cat_ID));
  27.         foreach ($subcategories as $subcategory) {
  28.             echo '<span class="subcategory" style="padding-left:12px">';
  29.             echo '<a href="">'.$subcategory->cat_name.'</a></span>';
  30.         }
  31.        
  32.     else : //#not the top cat//
  33.  
  34. //insert the (normal) loop to output the category posts if the cat is not top level//
  35.  
  36.     endif;
  37. }
  38.  
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement