• I’ve got a site with multiple major categories, each one having many subcategories. I want pages for each of them, and archives for each of them. I also want them styled differently from the regular blog page and single post pages.

    I found this solution to assigning different single.php templates depending on category:

    <?php
    	$post = $wp_query->post;
    	if (in_category('principle')) {
    			include(TEMPLATEPATH.'/single_principle.php');
    	} elseif (in_category('issue')) {
    			include(TEMPLATEPATH.'/single_issue.php');
    	}
    	else{
    			include(TEMPLATEPATH.'/single_default.php');
    	}
    ?>

    This works great, so I have that problem checked off. However, I also want to have separate sidebars for each major category page, with an archive feature for just that parent category. Nothing I do will accomplish this.

    Then I thought of simply using the same technique from above and make multiple archive templates. If I can direct to different pages, I can put the category ID in the loop. Well, it doesn’t break anything; but it doesn’t work, either. Using this

    <?php
    	$post = $wp_query->post;
    	if (in_category('principle')) {
    			include(TEMPLATEPATH.'/archive_principle.php');
    	}
    	elseif (in_category('issue')) {
    			include(TEMPLATEPATH.'/archive_issue.php');
    	}
    	else{
    			include(TEMPLATEPATH.'/archive_default.php');
    	}
    ?>

    every archive loads from archive_issue.php. Why it should do this is a complete mystery to me…I would have assumed that if it failed, everything would load from archive_default.php. In fact, if I delete archive_issue.php, it doesn’t default to another template…instead I get this:

    Warning: include(/home/domain/public_html/client_name/wp-content/themes/theme_name/archive_issue.php) [function.include]: failed to open stream: No such file or directory in /home/domain/public_html/client_name/wp-content/themes/theme_name/archive.php on line 7
    
    Warning: include() [function.include]: Failed opening '/home/domain/public_html/client_name/wp-content/themes/theme_name/archive_issue.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/domain/public_html/client_name/wp-content/themes/theme_name/archive.php on line 7

    Anyone have any insight into what’s going on?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to hack archive.php to allow single category archives?’ is closed to new replies.