Advertisement
alchymyth

cat template

Nov 21st, 2012
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  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.     endif; //ends   'if ($category->parent == $catid):'
  26.  
  27. }
  28.            
  29. else : //#not the top cat//
  30.  
  31. //insert the (normal) loop to output the category posts if the cat is not top level//
  32.  
  33. endif;
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement