• Resolved TrishaM

    (@trisham)


    Using WP 2.5 and trying to deliver a different page if the single post being clicked on is in a specific category, else deliver the standard single page.

    This code came directly from the Codex and modified only to use my actual category ID and include file

    <?php
         $post = $wp_query->post;
          if (in_category(16)) {
             include(TEMPLATEPATH . '/single-cat-16.php');
             }
    	     else {
             include(TEMPLATEPATH . '/single.php');
             }
    ?>

    However, even though I am positive that a post is within the category specified (16) – I even checked it using phpMyAdmin to be certain – WP is still using single.php, not single-cat-16.php for all single posts.

    In searching through the Codex and forums I came across information that said to use “is_category” instead of “in_category” if you are not using it within the Loop, so I tried that as well – made no difference.

    Is there something different about 2.5 and this function?

Viewing 4 replies - 16 through 19 (of 19 total)
  • Hello folks, been a while since I was on here! (Liking the new 2.5 Admin theme a lot)

    I have a similar problem – my blog template is incorrectly being applied to every page. I’ve double checked the category ids and that the is_child plugin is working… but… no luck…

    Any ideas?

    Here is my index.php page:

    <?php
    
     $post = $wp_query->post;
    
     if (is_child('Blog') || in_category('1')) {
    	// if blog article, use single page blog template
      	include(TEMPLATEPATH . '/index_blog.php');
     }
    else if(strstr($post->post_content,'<!--more-->')) {
    	// else if more tag found, use 2 column splitter layout
    	include(TEMPLATEPATH . '/index_image.php');
    
     } else {
    	// otherwise use default 1 column layout
    	include(TEMPLATEPATH . '/index_default.php');
    }
    
    ?>

    As suggested above I’ve also tried:

    <?php
    if ( have_posts() ) { the_post(); rewind_posts(); }
    
    if (is_child('Blog') || in_category('1')) {
    	// if blog article, use single page blog template
      	include(TEMPLATEPATH . '/index_blog.php');
     }
    else if(strstr($post->post_content,'<!--more-->')) {
    	// else if more tag found, use 2 column splitter layout
    	include(TEMPLATEPATH . '/index_image.php');
    
     } else {
    	// otherwise use default 1 column layout
    	include(TEMPLATEPATH . '/index_default.php');
    }
    
    ?>

    It’s like the other pages think they are in_category(‘1’) ????

    edit – confirmed, if I put the below on a static page, the output is ‘Blog’

    foreach((get_the_category()) as $category) {
        echo $category->cat_name . ' ';
    }

    Found an easy fix ??

    if (!is_page() && (is_child('Blog') || in_category('1')))

    Just a quick comment say that Otto’s reply here has really helped me out – thanks! showing category-specific content outside of the loop as been driving me mad for a long time! But not any more!

Viewing 4 replies - 16 through 19 (of 19 total)
  • The topic ‘in_category not working’ is closed to new replies.