Hey guys,

I need some help with the wordpress plugin fold category list. The purpose of the category is to create a category tree. I need to customize the php that when you click on the parent category, only the posts that are placed in the parent category show up. The posts that are placed in the child categories only should not show up.
Code below -

Code:
function _wswwpx_category_get_id ( $cat = '' ) {
	global $wpdb;
	// Make sure there is a cat identifier to process
	if (($wp_version = get_bloginfo('version')) < VERSION_SWITCH) {
		$field = 'cat_ID';
		$table = $wpdb->categories;
		$where = 'category_nicename';
	} else {
		$field = 'term_ID';
		$table = $wpdb->terms;
		$where = 'name';
	}
	if ( !is_numeric($cat) && strlen($cat) > 0 ) {
		
		$cats = explode(';', $cat, 2);
		$cats = explode('/', $cats[0]);
		$n = count($cats);
		$cats = array_reverse(array_slice($cats, 0, $n-1));
		$result = $wpdb->get_var("
									SELECT $field
										FROM $table
										WHERE $where = '{$cats[0]}'");
	} else if (is_numeric($cat)) {
	
		$result = $cat;
	} else {
		
		$result = 0;
	}
	//
	return $result;
}


function _wswwpx_category_get_parent_id ( $child = 0 ) {
	global $wpdb;
	if (($wp_version = get_bloginfo('version')) < VERSION_SWITCH) {
		$field = 'category_parent';
		$table = $wpdb->categories;
		$where = 'cat_ID';
	} else {
		$field = 'parent';
		$table = $wpdb->term_taxonomy;
		$where = 'term_ID';
	}
	if ( is_numeric($child) && $child > 0 ) {
		$result = $wpdb->get_var("
									SELECT $field
										FROM $table
										WHERE $where = $child");
	} else {
		$result = 0;
	}
	//
	return $result;
}

function _wswwpx_category_get_name ( $cid = 0 ) {
	global $wpdb;
	// Make sure there is a child ID to process
	if (($wp_version = get_bloginfo('version')) < VERSION_SWITCH) {
		$field = 'cat_name';
		$table = $wpdb->categories;
		$where = 'cat_ID';
	} else {
		$field = 'name';
		$table = $wpdb->terms;
		$where = 'term_ID';
	}
	if ( is_numeric($cid) && $cid > 0 ) {
		$result = $wpdb->get_var("
									SELECT $field
										FROM $table
										WHERE $where = $cid");
	} else {
		$result = NULL;
	}
	//
	return $result;
}


function _wswwpx_category_get_ancestor_ids ( $child = 0, $inclusive=true, $topdown=true ) {
	
	$child = _wswwpx_category_get_id ($child);
	
	if ( $child && $inclusive ) $ancestors[] = $child;
 	while ($parent = _wswwpx_category_get_parent_id ( $child ) ) {
 		$ancestors[] = $parent;
 		$child = $parent;
 	}
 	//	If there are ancestors, test for resorting, and apply
 	if ($ancestors && $topdown) krsort($ancestors);
	if ( !$ancestors ) $ancestors[] = 0;
 	//
 	return $ancestors;
 }


function _wswwpx_category_get_child_ids ( $parent = 0 ) {
	global $wpdb;
	if (($wp_version = get_bloginfo('version')) < VERSION_SWITCH) {
		$field = 'cat_ID';
		$table = $wpdb->categories;
		$where = 'category_parent';
	} else {
		$field = 'term_ID';
		$table = $wpdb->term_taxonomy;
		$where = 'parent';
	}

	if ( is_numeric($parent) && $parent > 0 ) {
		// Get the ID of the parent.
		$results = $wpdb->get_results("
									SELECT $field
										 FROM $table
										 WHERE $where = $parent");

 		if ($results) {
			foreach ($results AS $r) {
			 	foreach ($r AS $v) {
			 		$result[] = $v;
			 	}
			 }
		} else {
			$result = false;
		}
	} else {
		$categories = get_cats();
		if (($wp_version = get_bloginfo('version')) < VERSION_SWITCH) {
			foreach ($categories AS $category) {
				$result[]=$category->cat_ID;
			}
		} else {
			foreach ($categories AS $category) {
				$result[]=$category->term_ID;
			}
		}

//		$result = false;
	}
	//
	return $result;
}

 /*
  * _wswwpx_category_get_descendant_ids
  *  - $parent is the ID of a category
  *  - $inclusive is a switch determining whether the parent ID is included in the returned array. Defaults TRUE
  *  - returns an array of IDs of all descendents of the requested category
  */
function _wswwpx_category_get_descendant_ids ( $parent = 0, $inclusive=true ) {
 	if ( $parent && $inclusive ) $descendants[] = $parent;
 	if ( $offspring = _wswwpx_category_get_child_ids ( $parent ) ) {
		if (is_array($offspring) && is_array($descendants) ) {
			$descendants = array_merge($descendants, $offspring);
		} else  if (is_array($offspring)){
			$descendants = $offspring;
		}
 		foreach ( $offspring as $child ) {
 			$grandchildren = _wswwpx_category_get_descendant_ids ( $child, false );
	 		if (is_array($grandchildren) && is_array($descendants)) {
	 			$descendants = @array_merge($descendants, $grandchildren);
	 		} else if (is_array($grandchildren)) {
	 			$descendants = $grandchildren;
	 		}
 		}
 	}
 	//
 	return $descendants;
 }



/*	F R O N T   E N D   Functions
 *-----------------------------------------------------------------------
 *	The following are taken from WP itself, and modified.
 * Modifed versions of:
 *		wp_list_cats: wswwpx_fold_category_list
 *		list_cats:    wswwpx_list_cats
 *
 *	Original comments from WP are left in place
 *
 */
   function wswwpx_fold_category_list ($args = '') {
   	parse_str($args, $r);
   	if (!isset($r['optionall'])) $r['optionall'] = 0;
       if (!isset($r['all'])) $r['all'] = 'All';
   	if (!isset($r['sort_column'])) $r['sort_column'] = 'ID';
   	if (!isset($r['sort_order'])) $r['sort_order'] = 'asc';
   	if (!isset($r['file'])) $r['file'] = '';
   	if (!isset($r['list'])) $r['list'] = true;
   	if (!isset($r['optiondates'])) $r['optiondates'] = 0;
   	if (!isset($r['optioncount'])) $r['optioncount'] = 0;
   	if (!isset($r['hide_empty'])) $r['hide_empty'] = 1;
   	if (!isset($r['use_desc_for_title'])) $r['use_desc_for_title'] = 1;
   	if (!isset($r['children'])) $r['children'] = true;
   	if (!isset($r['child_of'])) $r['child_of'] = 0;
   	if (!isset($r['categories'])) $r['categories'] = 0;
   	if (!isset($r['recurse'])) $r['recurse'] = 0;
   	if (!isset($r['feed'])) $r['feed'] = '';
   	if (!isset($r['feed_image'])) $r['feed_image'] = '';
   	if (!isset($r['exclude'])) $r['exclude'] = '';
   	if (!isset($r['hierarchical'])) $r['hierarchical'] = true;
// WSW Extras
   	if (isset($r['cut_desc'])) $cut_desc = $r['cut_desc'];
   	if (isset($r['expand']))  $expandlist = $r['expand'];

	if (($wp_version = get_bloginfo('version')) < VERSION_SWITCH) {
		wswwpx_list_cats($r['optionall'], $r['all'], $r['sort_column'], $r['sort_order'], $r['file'],	$r['list'], $r['optiondates'], $r['optioncount'], $r['hide_empty'], $r['use_desc_for_title'], $r['children'], $r['child_of'], $r['categories'], $r['recurse'], $r['feed'], $r['feed_image'], $r['exclude'], $r['hierarchical'], $cut_desc, $expandlist);
	} else {
		if (!isset($r['orderby'])) $r['orderby'] = 'name';
		if (!isset($r['order']))  $r['order'] = 'ASC';
		if (!isset($r['title_li'])) $r['title_li'] = __('');
	   	if (!isset($r['style'])) $r['style'] = 'list';
		wswwpx_list_cats23($r['optionall'], $r['all'], $r['title_li'], $r['orderby'], $r['order'], $r['file'],	$r['style'], $r['optiondates'], $r['optioncount'], $r['hide_empty'], $r['use_desc_for_title'], $r['children'], $r['child_of'], $r['categories'], $r['recurse'], $r['feed'], $r['feed_image'], $r['exclude'], $r['hierarchical'], $cut_desc, $expandlist);
	}
   }
/*
//
//	Main driving function for WP versions prior to 2.3.1
//
*/
   function wswwpx_list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = '', $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1, $use_desc_for_title = 1, $children=FALSE, $child_of=0, $categories=0, $recurse=0, $feed = '', $feed_image = '', $exclude = '', $hierarchical=FALSE, $cut_desc='', $expandlist=0) {
   	global $wpdb, $category_posts, $wp_query;

//	Added for folding functionality... fix for permalink compatibility and modified after further suggestion from Laurence O.
		if (is_category()) {
			$current_cat = $wp_query->get_queried_object_id();
			$all_ancestors = _wswwpx_category_get_ancestor_ids($current_cat);
		} elseif (is_single()) {
			//
			//	Single posts (courtesy http://www.pqdb.com/wordpress-articles/using-wordpress-as-a-cms-content-management-system/)
			//	Returns the first category if more than one assignment, so may break navigational 'clarity'
			//
			$cat = get_the_category();
			$cat = $cat[0];
			$cat_ID = get_cat_ID($cat_name=$cat->cat_name);
			// get category ID for given category name
			$current_cat = $cat_ID;
			$all_ancestors = _wswwpx_category_get_ancestor_ids($current_cat);
		} else {
			//
			//	Default to zero for all other cases.
			//
			$all_ancestors[] = 0;
		}
/*//	Old version... replaced by above for greater compatibility with WP CORE
		if (isset($_GET['category_name'])) {
			$all_ancestors = _wswwpx_category_get_ancestor_ids($_GET['category_name']);
		} else if (isset($_GET['cat'])) {
			$all_ancestors = _wswwpx_category_get_ancestor_ids($_GET['cat']);
		} else {
			//
			//	Default to zero for all other cases.
			//
			$all_ancestors[] = 0;
		} */
//	End add
   	// Optiondates now works
   	if ('' == $file) {
   		$file = get_settings('home') . '/';
   	}

   	$exclusions = '';
   	if (!empty($exclude)) {
   		$excats = preg_split('/[\s,]+/',$exclude);
   		if (count($excats)) {
   			foreach ($excats as $excat) {
   				$exclusions .= ' AND cat_ID <> ' . intval($excat) . ' ';
   			}
   		}
   	}

   	$exclusions = apply_filters('list_cats_exclusions', $exclusions);

   	if (intval($categories)==0){
   		$sort_column = 'cat_'.$sort_column;

   		$query  = "
   			SELECT cat_ID, cat_name, category_nicename, category_description, category_parent
   			FROM $wpdb->categories
   			WHERE cat_ID > 0 $exclusions
   			ORDER BY $sort_column $sort_order";

   		$categories = $wpdb->get_results($query);
   	}
   	if (!count($category_posts)) {
   		$now = current_time('mysql', 1);
   		$sql = "SELECT cat_ID,
   					COUNT($wpdb->post2cat.post_id) AS cat_count
   					FROM $wpdb->categories 
   					INNER JOIN $wpdb->post2cat ON (cat_ID = category_id)
   					INNER JOIN $wpdb->posts ON (ID = post_id)
   					WHERE post_status = 'publish'";
   		if (($wp_version = get_bloginfo('version')) >= 2.1) $sql .= " AND post_type = 'post'";
   		$sql .= " AND post_date_gmt < '$now' $exclusions
   					GROUP BY category_id";
   		$cat_counts = $wpdb->get_results($sql);
           if (! empty($cat_counts)) {
               foreach ($cat_counts as $cat_count) {
                   if (1 != intval($hide_empty) || $cat_count > 0) {
                       $category_posts["$cat_count->cat_ID"] = $cat_count->cat_count;
                   }
               }
           }
   	}
   	
   	if ( $optiondates ) {
   		$cat_dates = $wpdb->get_results("	SELECT category_id,
   		UNIX_TIMESTAMP( MAX(post_date) ) AS ts
   		FROM $wpdb->posts, $wpdb->post2cat
   		WHERE post_status = 'publish' AND post_id = ID $exclusions
   		GROUP BY category_id");
   		foreach ($cat_dates as $cat_date) {
   			$category_timestamp["$cat_date->category_id"] = $cat_date->ts;
   		}
   	}
   	
   	$num_found=0;
   	$thelist = "";



   	foreach ($categories as $category) {
//
//	Add ability to have running totals, not just in category counts in the list.
//
		$all_children = _wswwpx_category_get_descendant_ids($category->cat_ID);
		$runningTotal = 0;
		foreach ($category_posts AS $k=>$v) {
			if (@in_array($k, $all_children) ) $runningTotal += $v;
		}
   		if (((intval($hide_empty) == 0 || (intval($hide_empty) == 2 && $runningTotal > 0)) || isset($category_posts["$category->cat_ID"])) && (!$hierarchical || $category->category_parent == $child_of) ) {
   			$num_found++;
//
//	WSW Deaden the link to the current category, and tag ancestor links for different styling
//	Adds one further conditional
//
			if ($category->cat_ID == $current_cat) {
				$link = wp_specialchars($category->cat_name);
			} else {
				//
				//	WSW Check for whether an ancestor of the current category
				//
				if (in_array($category->cat_ID, $all_ancestors)) {
					$link_class = 'class="current_cat_ancestor"';
				} else {
					$link_class = '';
				}
				$link = '<a ' . $link_class . ' href="'.get_category_link($category->cat_ID).'" ';
				if ($use_desc_for_title == 0 || empty($category->category_description)) {
					$link .= 'title="'. sprintf(__("View all posts filed under %s"), wp_specialchars($category->cat_name)) . '"';
				} else {
//
//	WSW change to allow for truncated descriptions within link titles.
//
//   					$link .= 'title="' . wp_specialchars(apply_filters('category_description',$category->category_description,$category)) . '"';
						$link .= 'title="' . wp_specialchars(wswwpx_category_description($category, $cut_desc, 0)) . '"';
				}
				$link .= '>';
				$link .= apply_filters('list_cats', $category->cat_name, $category).'</a>';
			}
//
//	End current link deadening...
//

   			if ( (! empty($feed_image)) || (! empty($feed)) ) {
   				
   				$link .= ' ';

   				if (empty($feed_image)) {
   					$link .= '(';
   				}

   				$link .= '<a href="' . get_category_rss_link(0, $category->cat_ID, $category->category_nicename)  . '"';

   				if ( !empty($feed) ) {
   					$title =  ' title="' . $feed . '"';
   					$alt = ' alt="' . $feed . '"';
   					$name = $feed;
   					$link .= $title;
   				}

   				$link .= '>';

   				if (! empty($feed_image)) {
   					$link .= "<img src='$feed_image' $alt$title" . ' />';
   				} else {
   					$link .= $name;
   				}
   				
   				$link .= '</a>';

   				if (empty($feed_image)) {
   					$link .= ')';
   				}
   			}
   			if (intval($optioncount) == 1) {
   				$link .= ' ('.intval($category_posts["$category->cat_ID"]).')';
   			} else if (intval($optioncount) == 2) {
//
//	Handle running count option here...
//
    			$link .= ' ('.$runningTotal.')';
  			}
   			if ( $optiondates ) {
   				if ( $optiondates == 1 ) $optiondates = 'Y-m-d';
   				$link .= ' ' . gmdate($optiondates, $category_timestamp["$category->cat_ID"]);
   			}
   			if ($list) {
   				$thelist .= "\t<li>$link\n";
   			} else {
   				$thelist .= "\t$link<br />\n";
   			}

//	Extra 'if' added for folding functionality
   			if (in_array($category->cat_ID, $all_ancestors) || $expandlist == 1) {
	   			if ($hierarchical && $children) $thelist .= wswwpx_list_cats($optionall, $all, $sort_column, $sort_order, $file, $list, $optiondates, $optioncount, $hide_empty, $use_desc_for_title, $hierarchical, $category->cat_ID, $categories, 1, $feed, $feed_image, $exclude, $hierarchical, $cut_desc, $expandlist);
			}
//	End add
   			if ($list) $thelist .= "</li>\n";
   		}
   	}
   	if (!$num_found && !$child_of){
   		if ($list) {
   			$before = '<li>';
   			$after = '</li>';
   		}
   		echo $before . __("No categories") . $after . "\n";
   		return;
   	}
   	if ($list && $child_of && $num_found && $recurse) {
   		$pre = "\t\t<ul class='children'>";
   		$post = "\t\t</ul>\n";
   	} else {
   		$pre = $post = '';
   	}
   	$thelist = $pre . $thelist . $post;
   	if ($recurse) {
   		return $thelist;
   	}
   	echo apply_filters('list_cats', $thelist);
   }
/*
//
//	Main driving function for WP versions after WP version 2.3
//
*/
   function wswwpx_list_cats23($optionall = 1, $all = 'All', $title_li='Categories', $sort_column = 'ID', $sort_order = 'asc', $file = '', $style = 'list', $optiondates = 0, $optioncount = 0, $hide_empty = 1, $use_desc_for_title = 1, $children=FALSE, $child_of=0, $categories=0, $recurse=0, $feed = '', $feed_image = '', $exclude = '', $hierarchical=FALSE, $cut_desc='', $expandlist=0) {
   	global $wpdb, $category_posts, $wp_query;

//	Added for folding functionality... fix for permalink compatibility and modified after further suggestion from Laurence O.
		if (is_category()) {
			$current_cat = $wp_query->get_queried_object_id();
			$all_ancestors = _wswwpx_category_get_ancestor_ids($current_cat);
		} elseif (is_single()) {
			//
			//	Single posts (courtesy http://www.pqdb.com/wordpress-articles/using-wordpress-as-a-cms-content-management-system/)
			//	Returns the first category if more than one assignment, so may break navigational 'clarity'
			//
			$cat = get_the_category();
			$cat = $cat[0];
			$cat_ID = get_cat_ID($cat_name=$cat->cat_name);
			// get category ID for given category name
			$current_cat = $cat_ID;
			$all_ancestors = _wswwpx_category_get_ancestor_ids($current_cat);
		} else {
			//
			//	Default to zero for all other cases.
			//
			$all_ancestors[] = 0;
		}