• I’d like to force a category to actually use the single-categoryname.php template instead of the normal category-name.php template if the post count is 1. Here’s the code I’m currently using without success:

    add_action('category_template', 'use_single_for_one_category');
    function use_single_for_one_category($template = '') {
            global $wp_query;
            if ( 1 === (int) $wp_query->post_count ) {
                    $template = get_single_template();
            }
            return $template;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • I’m not a php expert, but don’t you have syntax error at ===?

    Thread Starter ajohnson

    (@ajohnson)

    no thats not an error per say, but perhaps not what I should be using. Even using == it doesn’t work. Thanks for any advice!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘if post count = 1 use single-catname.php’ is closed to new replies.