Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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(); ?>
share|improve this question

1 Answer 1

up vote 2 down vote accepted

You can create a category template named category-foo.php this will be applied only to category with slug foo. You can thus create custom template for different categories.

Source - Codex page for Category template

Note -

If you want to do some minor changes such as show foo in a category-1 and bar on other, then It'd be good to have a single category.php and use is_category conditional tags.


Update -

You can use get_template_part( $slug, $name ) to use different loops for different categories -

<?php 
if (is_category('foo')) {
    get_template_part( 'cat', 'foo' );  // It'll load    cat-foo.php
} else (is_category('bar')) {
    get_template_part( 'cat', 'bar' );  //   cat-bar.php
} else { 
    //
}
?>
share|improve this answer
    
perfect. Thanks for you reply. I appreciate it. Can I create an alternate loop using the same idea? –  Keefer Aug 13 '12 at 17:49
1  
using conditions? yes you can –  amit Aug 13 '12 at 17:53
1  
If I'm not wrong I've updated my answer with an example you're looking for ;) –  amit Aug 13 '12 at 18:02
    
Great! Thanks again. –  Keefer Aug 13 '12 at 18:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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