View difference between Paste ID: 5KjhYFCH and wGrQ6sP5
SHOW: | | - or go back to the newest paste.
1
<?php		
2-
//# first of all, you need to get the category array,
2+
3-
//   and I did it, putting the line bellow inside the loop
3+
$catid = get_query_var('cat');
4-
$category = get_the_category(get_the_ID());
4+
$cat = get_category( $catid );
5
6-
// once you have the category array, the rest of the code will work wherever you want on the page 
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-
$catid=$category[0]->category_parent;
9+
10-
if($catid==0){
10+
11-
  $catid=$category[0]->cat_ID;
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-
    if ($category->parent ==$catid):
19+
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
?>