Forum Replies Created

Viewing 1 replies (of 1 total)
  • I just found a better solution, combining the two first solutions.
    In a file named functions.php located in my template folder, I copied/pasted the functions get_the_category_list() and get_the_category(), I renamed these functions in get_the_category_list_excludeCat() and get_the_category_excludeCat() with two little changes :

    • changed the function get_the_category into get_the_category_excludeCat() in the function get_the_category_list_excludeCat()
    • excluded a category in the function get_the_category_excludeCat()

    My english is sooo bad, so check the following code, I think it would be more clear.

    function get_the_category_list_excludeCat($separator = '', $parents='') {
    	global $wp_rewrite;
            // change the function get_the_category into get_the_category_excludeCat()
    	$categories = get_the_category_excludeCat();
    	if (empty($categories))
    		return apply_filters('the_category', __('Uncategorized'), $separator, $parents);
    
    	$rel = ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"';
    
    	$thelist = '';
    	if ( '' == $separator ) {
    		$thelist .= '<ul class="post-categories">';
    		foreach ( $categories as $category ) {
    			$thelist .= "\n\t<li>";
    			switch ( strtolower($parents) ) {
    				case 'multiple':
    					if ($category->parent)
    						$thelist .= get_category_parents($category->parent, TRUE);
    					$thelist .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . $rel . '>' . $category->name.'</a></li>';
    					break;
    				case 'single':
    					$thelist .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . $rel . '>';
    					if ($category->parent)
    						$thelist .= get_category_parents($category->parent, FALSE);
    					$thelist .= $category->name.'</a></li>';
    					break;
    				case '':
    				default:
    					$thelist .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . $rel . '>' . $category->cat_name.'</a></li>';
    			}
    		}
    		$thelist .= '</ul>';
    	} else {
    		$i = 0;
    		foreach ( $categories as $category ) {
    			if ( 0 < $i )
    				$thelist .= $separator . ' ';
    			switch ( strtolower($parents) ) {
    				case 'multiple':
    					if ( $category->parent )
    						$thelist .= get_category_parents($category->parent, TRUE);
    					$thelist .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . $rel . '>' . $category->cat_name.'</a>';
    					break;
    				case 'single':
    					$thelist .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . $rel . '>';
    					if ( $category->parent )
    						$thelist .= get_category_parents($category->parent, FALSE);
    					$thelist .= "$category->cat_name</a>";
    					break;
    				case '':
    				default:
    					$thelist .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . $rel . '>' . $category->name.'</a>';
    			}
    			++$i;
    		}
    	}
    
    	return apply_filters('the_category', $thelist, $separator, $parents);
    }
    
    function get_the_category_excludeCat($id = false) {
    	global $post, $term_cache, $blog_id;
    
    	$id = (int) $id;
    	if ( !$id )
    		$id = (int) $post->ID;
    
    	$categories = get_object_term_cache($id, 'category');
    	if ( false === $categories )
    		$categories = wp_get_object_terms($id, 'category');
    
    	//exclude cat 3 :
    	unset($categories[3]);		
    
    	if ( !empty($categories) )
    		usort($categories, '_usort_terms_by_name');
    	else
    		$categories = array();
    
    	foreach(array_keys($categories) as $key) {
    		_make_cat_compat($categories[$key]);
    	}
    
    	return $categories;
    }
Viewing 1 replies (of 1 total)