Category List (Archive) Page Template By Category

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?

Read More

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(); ?>

Related posts

Leave a Reply

1 comment

  1. 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 { 
        //
    }
    ?>