I feel like this is probably a duplicate question, but cannot find the search terms to find what I’m looking for.
Is it possible to have different category list (archive) pages (or views/templates) based on the post’s category?
I’m working on a site that’s using the blog as a top-level category, but I want my other “pages” to just be other top level post categories, each with a custom look for the category list/archive page.
Example:
Going to /category/blog outputs the default category.php output, listing out all the recent blog posts (that are categorized with the top-level category of blog, or are children categories of blog)
Going to /category/work lists out all recent work entries (that are categorized with the top-
level category of “work” and any children categories)
Is this possible?
Edit: Here’s how I have my category.php page setup (basing this “custom” template on the twenty_ten obviously. At this point, would I just modify the get_template_part('loop', 'category');
part in the work if statement to point to something different than “loop?”
<?php
/**
* The template for displaying Category Archive pages.
*
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.0
*/
if (is_category('blog')) :
$GLOBALS['pagetype'] = 'blog';
endif;
if (is_category('work')) :
$GLOBALS['pagetype'] = 'work';
endif;
get_header(); ?>
<div id="container">
<!-- OUTPUT FOR BLOG CATEGORY LIST PAGE -->
<?php if (is_category('blog')) : ?>
<div id="content" class="blogList" role="main">
<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo '<div class="archive-meta">' . $category_description . '</div>';
/* Run the loop for the category page to output the posts.
* If you want to overload this in a child theme then include a file
* called loop-category.php and that will be used instead.
*/
get_template_part( 'loop', 'category' );
?>
<div class="triangle"></div>
</div><!-- #content -->
<?php endif; ?>
<!-- /OUTPUT FOR BLOG CATEGORY LIST PAGE -->
<!-- OUTPUT FOR WORK CATEGORY LIST PAGE -->
<?php if (is_category('work')) : ?>
<div id="content" class="blogList" role="main">
<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo '<div class="archive-meta">' . $category_description . '</div>';
/* Run the loop for the category page to output the posts.
* If you want to overload this in a child theme then include a file
* called loop-category.php and that will be used instead.
*/
get_template_part( 'loop', 'category' );
?>
<div class="triangle"></div>
</div><!-- #content -->
<?php endif; ?>
<!-- /OUTPUT FOR WORK CATEGORY LIST PAGE -->
</div><!-- #container -->
<!--Default sidebar only for Blog postings-->
<?php if (is_category('blog')) :
get_sidebar();
endif;
?>
<?php get_footer(); ?>
You can create a category template named
category-foo.php
this will be applied only to category with slugfoo
. You can thus create custom template for different categories.Source – Codex page for Category template
Update –
You can use
get_template_part( $slug, $name )
to use different loops for different categories –