Forum Replies Created

Viewing 1 replies (of 1 total)
  • I helped myself by introducing the children=0parameter to wp-includes/categeroy-template.php file inside the function function wp_list_categories($args = ''). I placed the following code snippet pretty at the top of the function (after the line $r = wp_parse_args( $args, $defaults );):

    if ( isset($r['children']) ) {
    		if($r['children'] == 0) {
    			$query = "SELECT w.term_id AS id FROM wp_terms w, wp_term_taxonomy t
    						WHERE t.term_id = w.term_id AND
    						t.taxonomy = 'category' AND
    						t.parent = 0 ORDER BY w.name";
    			$tlc_ids = $wpdb->get_results($query);
    			foreach($tlc_ids as $c) {
    				$tlcs[] = get_category($c->id);
    			} /* now we have all top level category objects. */
    
    			/* Which is the active category? */
    			if($_SERVER['REQUEST_METHOD'] == 'GET') {
    				if(isset($_GET[cat])) {
    					$current_cat_id = $_GET[cat];
    				}
    				else {
    					$current_cat_id = NULL;
    				}
    
    				/* Let's mark the active top level category. */
    				foreach($tlcs as $cat) {
    					if("{$cat->term_id}" == $current_cat_id) {
    						$cat->active = true;
    					}
    					else {
    						$cat->active=false;
    					}
    					$res[]=$cat;
    				}
    				$tlcs = $res;
    			}
    			return $tlcs;
    		}
    	}

    It may not be the best solution but it does the job for me: Just gives me all top level categories only!

Viewing 1 replies (of 1 total)