WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have found a tutorial online for creating a custom categories template for my archived posts within a particular category. This however is targetting a specific category ID (see below), is there anyway of creating a template that targets all rather than one specific ID?

Template Name: Category-Tutorials
 * The template for displaying Archive pages.
 * Used to display archive-type pages if nothing more specific matches a query.
 * For example, puts together date-based pages if no date.php file exists.
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0

get_header(); ?>

    <section id="primary">
        <div id="content" role="main">

<header class="page-header">
                <h1 class="page-title">
                    <?php if ( is_day() ) : ?>
                        <?php printf( __( 'Daily Archives: %s', 'twentyeleven' ), '<span>' . get_the_date() . '</span>' ); ?>
                    <?php elseif ( is_month() ) : ?>
                        <?php printf( __( 'Monthly Archives: %s', 'twentyeleven' ), '<span>' . get_the_date( 'F Y' ) . '</span>' ); ?>
                    <?php elseif ( is_year() ) : ?>
                        <?php printf( __( 'Yearly Archives: %s', 'twentyeleven' ), '<span>' . get_the_date( 'Y' ) . '</span>' ); ?>
                    <?php else : ?>
                        <?php _e( 'Tutorials', 'twentyeleven' ); ?>
                    <?php endif; ?>

    <ul class="category-7">
        <?php $archive_query = new WP_Query('cat=7&showposts=1000');
        while ($archive_query->have_posts()) : $archive_query->the_post(); ?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>
        <?php endwhile; ?>

        </div><!-- #content -->
    </section><!-- #primary -->

I was thinking maybe the following could be changed:

<?php $archive_query = new WP_Query('cat=7&showposts=1000');
share|improve this question
If you find the answer to your own question, that's great! Please post your solution as an answer, rather than editing it into the question itself. – Chip Bennett Dec 19 '12 at 17:26
Hi Chip, i did post this i believe as an answer.... 0_o... sorry for the confusion there :) – Kirsty Marks Dec 19 '12 at 17:42
Kirsty: I only see one answer: the one posted by @userabuser. – Chip Bennett Dec 19 '12 at 17:53
Hi Chip, not sure what happened then, as i know that i saw an edit. I must have posted it in the wrong box. Apologies – Kirsty Marks Dec 19 '12 at 18:20
I do see an edit to your question, that includes your solution. You just need to move that solution from your question, into an answer. :) – Chip Bennett Dec 19 '12 at 18:49

Remove the cat parameter from your query and name your template file category.php

From the WordPress Codex on Template Hierarchy;

 1. category-{slug}.php - If the category's slug were news, WordPress would look for category-news.php
 2. category-{id}.php - If the category's ID were 6, WordPress would look for category-6.php
 3. category.php
 4. archive.php
 5. index.php

The above denotes the order in which WordPress searches for template files and if it finds one that exists in that hierarchy, it will be used as the template for said condition.

So in this case you want to use category.php to create a global category template.

Of course, you can get creative and do all manner of things to meet all manner of conditions but if your basic requirement is as you describe then the above will suffice.


Replace this:

<ul class="category-7">
    <?php $archive_query = new WP_Query('cat=7&showposts=1000');
    while ($archive_query->have_posts()) : $archive_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>

...with this:

<ul class="category-7">
    <?php while ( have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
share|improve this answer
Actually, get rid of the custom query code entirely. Just name the template file category.php, and WordPress will use it for all category archive index pages. – Chip Bennett Dec 19 '12 at 17:25

I thought i would contribute my answer to the above. I have coded this to display my categories with a date, the person who posted it and a time it was posted, with a main title to display the title of the category in question.

Please see code and screenshot of what this produces, i hope this proves useful :)

<?php get_header(); ?>
<div id="maincontentwrap" role="main">
<h1 class="page-title"><?php
printf( __( 'Category Archives: %s', 'D-Theme' ), '<span>' . single_cat_title( '', false ) . '</span>' );
<div class="pagedivider"></div>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
Written by <?php the_author_posts_link() ?> in <?php the_category(); ?> at <?php the_time('H:h a'); ?> 
<div class="pagedivider"></div>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<?php get_footer(); ?>

Unfortunately i cannot screenshot due to lack of reputation on here, however i will show you my site so that you can see this in action.

share|improve this answer

Your Answer


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.