0

I've got a small issue with my archive.php. I was trying to set up an If statement that displays a certain category and sub categories with a different layout & sidebar based on my theme options. I've placed a small bit of code in the start of my archive.php in order to set these options based on if the post is in category 'nytt' or is a sub cat of nytt (ID 49). It works like a charm, if the category listing in part of NYTT or a sub cat, but now, all other categories don't display, the page won't load further than the header. And for the life of me I can't figure out why. I'm staring at this code like it holds a secret which it won't give up..

<?php
get_header();

$subtitle=get_opt("_posts_subtitle");
$slider='none';
if ( in_category( 'nytt' ) || post_is_in_descendant_category( 49 ) ) {
    $layout='left';
$sidebar ='teacher-training';
}
else { 
$layout = get_opt('_blog_layout');
$sidebar = get_opt('_blog_sidebar');
}

include(TEMPLATEPATH . '/includes/page-header.php');

?>

<div id="content-container" class="content-gradient <?php echo $layoutclass; ?> ">
<div id="<?php echo $content_id; ?>"><?php

if(have_posts()){
while(have_posts()){
    the_post();
    global $more;
    $more = 0;

include(TEMPLATEPATH . '/includes/post-template.php');  

} 

print_pagination(); 

}else{
echo ('No posts available');
}

?> 
</div>
<?php 
if($layout!='full'){
 print_sidebar($sidebar);
}
?>

<div class="clear"></div>
</div>
<?php
get_footer();
?>

Also I understand that I could be using the category.php to accomplish this as well, but as my theme was using archive.php by default I decided to use this instead. I've declared the [post_is_in_descendant_category] (http://codex.wordpress.org/Function_Reference/in_category#Testing_if_a_post_is_in_a_descendant_category)! function in my child themes functions.php.

Any help would be uber appreciated. Thanks for your time and expertise!

0

Firstly, do you have DEBUG set to TRUE in wp-config? Not loading further than the header may well mean there's an error that isn't displaying. Set it to True to see the error.

Secondly, you are using for in_category on an archive page - which I believe would only apply to the first post on the page. This may not make a difference in your case though.

Third, I would not use the default archive for this at all. I would create a template specifically for this category: category-nytt.php (see template hierarchy). This will both let you dispose of all the in_category/post_is_in_descendant_category gubbins entirely, and leave your default archive.php (once restored) to work in the standard way for standard posts.

EDIT:

See the answer here for having subcategories use their parent's template.

3
  • Hey @vancoder thanks for your suggestions. WP_Debug is set to false and from my understanding the category-[catname].php included in WP's template hierarchy doesn't work for sub-categories. My issue is that I have NYTT as a parent category and I want the custom layout properties outlined above to display when any of the sub-cats of NYTT are displayed in an archive or category format. – Andrew-ThinkUp Apr 11 '13 at 19:42
  • My point about WP_DEBUG was that you should set it to true to see the error. Answer updated. – vancoder Apr 11 '13 at 21:36
  • Thanks for your help on this. I followed your link for a solution to sub-categories using their parent's template and it came down to using this plugin which wickedly expands WP's template hierarchy.. http://wordpress.org/extend/plugins/category-template-hierarchy The first option he gave there didn't work for me although I tried it. Indeed WP_debug set to true revealed the errors. Thanks again for your time. I appreciate it greatly! – Andrew-ThinkUp Apr 25 '13 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.