Viewing 2 replies - 1 through 2 (of 2 total)
  • put the code below in your theme’s functions.php file. It designates certain categories that will not display in the cat listing, even if a post is assigned to them. See more instructions below

    function the_category_filter($thelist,$separator=' ') {
    	if(!defined('WP_ADMIN')) {
    		//Category IDs to exclude:  Homepage, Homepage Featured, Also Featured
    		$exclude = array(21,22,38);
    		$exclude2 = array();
    		foreach($exclude as $c) {
    			$exclude2[] = get_cat_name($c);
    		}
    		$cats = explode($separator,$thelist);
    		$newlist = array();
    		foreach($cats as $cat) {
    			$catname = trim(strip_tags($cat));
    			if(!in_array($catname,$exclude2))
    				$newlist[] = $cat;
    		}
    		return implode($separator,$newlist);
    	} else {
    		return $thelist;
    	}
    }
    // when adding cats to exclude list, last parameter (below) to match # of excluded cats
    add_filter('the_category','the_category_filter', 10, 3);

    Change this line
    $exclude = array(21,22,38);
    make the contents of the array a comma separated list of the category ID’s you want to exclude from displaying.

    The change this line
    add_filter('the_category','the_category_filter', 10, 3);

    the last “3” should be replaced with the # of cats you have entered in in the array list – for two cats, change the 3 to a 2.

    With this method the cats that are excluded are global across the whole site, not on a post by post basis.

    Thread Starter amagonagle

    (@amagonagle)

    Works great! I really appreciate it. Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show Category Name in Post’ is closed to new replies.