ThemeShaper Forums » Thematic

hiding category meta for 'uncategorized'

(2 posts)
  • Started 4 years ago by juanojeda
  • Latest reply from juanojeda
  • This topic is resolved
  1. Hi,
    I'm trying to customize my theme to only display categories in the postfooter IF the categories is NOT 'Uncategorized'(catid=1). The code I have so far is:

    $postcategory .= '<span class="cat-links">';
    	if () {
    		if (is_single()) {
    			$postcategory .= __('This entry was posted in ', 'thematic') . get_the_category_list(', ');
    			$postcategory .= '</span>';
    		} elseif ( is_category() && $cats_meow = thematic_cats_meow(', ') ) { /* Returns categories other than the one queried */
    			$postcategory .= __('Also posted in ', 'thematic') . $cats_meow;
    			$postcategory .= '</span> ';
    		} else {
    			$postcategory .= __('Posted in ', 'thematic') . get_the_category_list(', ');
    			$postcategory .= '</span> ';
    		}
    	}
    	else {
    		$postcategory = '';
    	}
        $postcategory = apply_filters('thematic_postfooter_postcategory',$postcategory);

    (thanks to Dannydamnboy in This thread).
    I wrapped the code in an if statement because I only want to display the $postcategory if the post has a category. However, I can't figure out what to put in the if brackets.

    Any suggestions?

    Posted 4 years ago #
  2. I've come up with a solution that works.

    //get category name and store as variable $category
    	function catname() {
    		foreach((get_the_category()) as $cat) {
    			return $cat->category_nicename;
    		}
    	}
    	$category = catname();
    
    	//when to display categories
    
    	//if the post has a real category display the category in footer links
    	if ($category != "uncategorized") {	
    
        $postcategory .= '<span class="cat-links">';
    	if (is_single()) {
    			$postcategory .= __('This entry was posted in ', 'thematic') . get_the_category_list(', ');
    			$postcategory .= '</span>';
    		} elseif ( is_category() && $cats_meow = thematic_cats_meow(', ') ) { /* Returns categories other than the one queried */
    			$postcategory .= __('Also posted in ', 'thematic') . $cats_meow;
    			$postcategory .= '</span> ';
    		} else {
    			$postcategory .= __('Posted in ', 'thematic') . get_the_category_list(', ');
    			$postcategory .= '</span> ';
    		}
    	}
    	//if the post is in the category 'uncategorized' don't display the categories
    	else {
    		$postcategory = '';
    	}
        $postcategory = apply_filters('thematic_postfooter_postcategory',$postcategory);

    (thanks to This article).

    and I've hidden the separator with CSS using

    body #main #container #content .category-uncategorized .entry-utility .meta-sep {
    	display: none;
    	}

    This may not be the most elegant solution, but I've only got a limited knowledge of php.

    If anyone has a suggestion for making this work in a cleaner way, I'd really appreciate it.

    Juan

    Posted 4 years ago #

RSS feed for this topic

Reply

You must log in to post.