Welcome, guest!

Feel free to read the blog, browse for themes, or join the club.

custom posts and categories, old way and new way?

  1. function structure_disable( $var ) {
    	return false;
    }
    function my_single_template($single) {
    	global $wp_query, $post;
    	/**
    	* Checks for single template by category
    	* Check by category slug and ID
    	*/
    	foreach((array)get_the_category() as $cat) :
    
    		if(file_exists(SINGLE_PATH . '/single-cat-' . $cat->slug . '.php'))
    			return SINGLE_PATH . '/single-cat-' . $cat->slug . '.php';
    
    		elseif(file_exists(SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php'))
    			return SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php';
    
    	endforeach;
    	/**
    	* Checks for default single post files within the single folder
    	*/
    	if(file_exists(SINGLE_PATH . '/single.php'))
    		return SINGLE_PATH . '/single.php';
    
    	elseif(file_exists(SINGLE_PATH . '/default.php'))
    		return SINGLE_PATH . '/default.php';
    			return $single;
    
    }

    The above is what I learned on one of your posts Justin. I really like doing it this way because a custom post does not have to be chosen. Would i change "single.php" to "post.php" here and it still work ok with the new hybrid?

  2. You must be a logged-in exclusive member to view this reply.

  3. good deal, thanks.

  4. Does this allow me to make a template for my posts to show them differently depending on the category that is selected?

    I am currently looking to change my layout depending on what category is selected.

    Thanks,
    Phil

  5. You must be a logged-in exclusive member to view this reply.

  6. taxonomy-category-news.php
    post-cat-news.php, these are the templates I am using in my child theme, along with the code above, although the custom category shows correctly, my post template does not show, it just defaults to post.php

  7. You must be a logged-in exclusive member to view this reply.

Reply

You must log in to post.

Limited Access

If you have an account, please take a moment to log in.

Non-exclusive members have limited access to the support forums.

To enjoy the full range of support, sign up for an exclusive membership in the theme club.

Support Forums

  • Bliss Theme (202 posts)
  • Hybrid Theme (17,034 posts)
  • Options Theme (10,322 posts)
  • Structure Theme (2,624 posts)
  • Visionary Theme (767 posts)
  • bbPress Themes (293 posts)
  • WordPress Plugins (1,617 posts)
  • General Discussion (3,979 posts)