WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Mar 09 2011

Create Your Own Custom Genesis Category Archive Template in WordPress

Someone in the StudioPress Support forums wanted a Category Archive Template that listed categories and posts under that category. For example:
Category 1

  • article 1
  • article 2
  • article n

Category 2

  • article 1
  • article 2
  • article n

So, here it is:

[php]<?php /** * Template Name: Category Archive */ get_header(); ?></p>
<p><?php genesis_before_content_sidebar_wrap(); ?></p>
<div id="content-sidebar-wrap">
<p> <?php genesis_before_content(); ?></p>
<div id="content">
<p> <?php genesis_before_loop(); ?></p>
<div class="post hentry">
<h1 class="entry-title"><?php _e("Site Archives", 'genesis'); ?></h1>
<div class="entry-content">
<p> <?php $categories = get_categories( $args );?> </p>
<ul class="catArchive">
<?php foreach ($categories as $category) { $catCounter++; $catLink=get_category_link($category->term_id);<br />
$catStyle = '';<br />
if (is_int($catCounter / 2)) $catStyle = ' class="catAlt"';</p>
<p> echo '<li'.$catStyle.'>
<h3><a href="'.$catLink.'" title="'.$category->name.'">'.$category->name.'</a></h3>
<p>';<br />
echo '
<ul>';</p>
<p> query_posts('cat='.$category->term_id.'&showposts=5');?></p>
<p> <?php while (have_posts()) : the_post(); ?></p>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<p> <?php endwhile; ?></p>
<li><a href="<?php echo $catLink; ?>" title="<?php echo $category->name; ?>">More <strong><?php echo $category->name; ?></strong></a></li>
</ul>
</li>
<p> <?php } ?>
</ul>
</div>
<p><!-- end .entry-content --></p>
</div>
<p><!-- end .post --><br />
<?php genesis_after_loop(); ?></p>
</div>
<p><!-- end #content --><br />
<?php genesis_after_content(); ?></p>
</div>
<p><!-- end #content-sidebar-wrap --><br />
<?php genesis_after_content_sidebar_wrap(); ?></p>
<p><?php get_footer(); ?><br />
[/php]

To add this to your child theme, simply follow these directions.
1. Open a blank text file.
2. Copy this code into it.
3. Save as page_catarchive.php (or just download: [download id="2"])
4. FTP into your child theme folder.

To use in your theme, create a new page and select Category Archive under Page Template.

Click Publish. Style via your CSS.

Written by Travis Smith · Categorized: Genesis, Tutorials

StudioPress Premium WordPress Themes     WP Engine Managed WordPress Hosting

What can I do for you!?

Custom Development

We develop plugins by determining both business/functional and technical requirements, following WordPress development best practices, and using agile methodology to ensure you get the best solution.

Consulting

Have questions? Need a reliable developer to consult? Please contact us today!

Customized Theme

We can customize your theme or child theme, or create a child theme for you based on your needs while enhancing the performance of every individual attribute.

Customized Plugin

We can customize your plugins, extend plugins (e.g., Gravity Forms, Jetpack, Soliloquy) based on your needs ensuring security, performance, and positive business impact.

Contact Us

About Travis Smith

As a WordPress enthusiast, developer, and speaker, Travis writes about what he learns in WordPress trying to help other WordPress travelers, beginners and enthusiasts with tutorials, explanations, & demonstrations.

Comments

  1. Kyle Goleno says

    March 13, 2011 at 3:35 pm

    I’ve used this and it works perfectly. However I wanted to modify it a bit, but am having some trouble. Instead of listing every category I wanted the page to have just one category, and the category to be defined in custom fields as “query_args” with a value of “cat=#”
    Do you have any suggestions?
    Thanks,
    Kyle

    Reply
  2. James Maabadi says

    November 12, 2011 at 5:25 pm

    Hi Kyle,
    You should be able to modify line 10 in the example above, add to only include the category you want to show in the get_categories() function. Reference for that function is here: http://codex.wordpress.org/Function_Reference/get_categories

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in