Title: need code help creating conditional archive template
Last modified: August 19, 2016

---

# need code help creating conditional archive template

 *  Resolved [wildbug](https://wordpress.org/support/users/wildbug/)
 * (@wildbug)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/need-code-help-creating-conditional-archive-template-1/)
 * I’m not a programmer but have picked up a small bit of stuff. I’m trying to create
   an archive template that shows only the clickable post title for a certain group
   of categories and for the rest, the thumbnail attachment, title, and excerpt (
   this is what it currently displays).
 * Is it best to create two separate archive templates and direct the template path
   based on categories, or to create 1 conditional archive template?
 * I tried both without complete success.
 * I used this code in archive.php:
 *     ```
       <?php
        if ( have_posts() ) { the_post(); rewind_posts(); }
        if ( in_category(4,5,6,7,8,9,10,453,454,455,456,457,458,459,460) ) {
        include(TEMPLATEPATH . '/archivesexperts.php');
        } else {
        include(TEMPLATEPATH . '/archives.php');
        }
        ?>
       ```
   
 * but it doesn’t seem to be working. Can anyone tell me if they see any problems
   with this code?
 * I also tried using 1 conditional archive template as shown below:
 *     ```
       <?php get_header(); ?>
   
       <!-- BEGIN content -->
       <div id="content">
   
       	<!-- BEGIN recent posts -->
       	<div class="span cbox arc">
       	<?php if (have_posts()) : $count = 0; ?>
       		<?php /* If this is a category archive */ if (is_category(4,5,6,7,8,9,10,453,454,455,456,457,458,459,460)) { ?>
       		<h2><?php fs_lang("Archive for "); ?> <strong><?php single_cat_title(); ?></strong></h2>
       		<?php } ?>
       		<ul>
       		<?php while (have_posts()) : the_post(); $count++; ?>
       		<li<?php if ($count==1) echo ' class="first"'; ?>>
       			<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
       		</li>
       		<?php endwhile; ?>
       		</ul>
       		<div class="postnav">
       			<div class="l"><?php next_posts_link('&laquo; '.fs_lang('Older Entries', false)); ?></div>
       			<div class="r"><?php previous_posts_link(fs_lang('Newer Entries', false).' &raquo;'); ?></div>
       		</div>
   
       	<?php elseif (have_posts()) : $count = 0; ?>
       		<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
       		<?php /* If this is a category archive */ if (is_category()) { ?>
       		<h2><?php fs_lang("Archive for "); ?> <strong><?php single_cat_title(); ?></strong></h2>
       		<?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
       		<h2><?php fs_lang("Posts Tagged "); ?> <strong><?php single_tag_title(); ?></strong></h2>
       		<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
       		<h2><?php fs_lang("Archive for "); ?> <?php the_time('F jS, Y'); ?></h2>
       		<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
       		<h2><?php fs_lang("Archive for "); ?> <?php the_time('F, Y'); ?></h2>
       		<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
       		<h2><?php fs_lang("Archive for "); ?> <?php the_time('Y'); ?></h2>
       		<?php /* If this is an author archive */ } elseif (is_author()) { ?>
       		<h2><?php fs_lang("Author Archive"); ?> </h2>
       		<?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
       		<h2><?php fs_lang("Blog Archives"); ?></h2>
       		<?php } ?>
       		<ul>
       		<?php while (have_posts()) : the_post(); $count++; ?>
       		<li<?php if ($count==1) echo ' class="first"'; ?>>
       			<a class="attachment" href="<?php the_permalink(); ?>"><?php fs_attachment_image($post->ID, 'thumbnail', 'alt="' . $post->post_title . '"'); ?></a>
       			<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
       			<p><?php echo fs_clean($post->post_excerpt); ?></p>
       		</li>
       		<?php endwhile; ?>
       		</ul>
       		<div class="postnav">
       			<div class="l"><?php next_posts_link('&laquo; '.fs_lang('Older Entries', false)); ?></div>
       			<div class="r"><?php previous_posts_link(fs_lang('Newer Entries', false).' &raquo;'); ?></div>
       		</div>
       	<?php else: ?>
       		<h2><?php fs_lang("Not Found"); ?></h2>
       		<p><?php fs_lang("You are searching for something that isn't here."); ?></p>
       	<?php endif; ?>
       	</div>
       	<!-- END recent posts -->
   
       </div>
       <!-- END content -->
   
       <?php get_sidebar(); get_footer(); ?>
       ```
   
 * but with the above code, I see these problems:
    • ALL category archive pages 
   missing “ARCHIVES FOR [CATEGORY NAME]” title  • “If” categories are correctly
   showing post titles only but “Else if” categories are as well when they should
   be showing the image attachment and excerpt as well
 * Can someone tell me how to fix either of the above options to work properly?
 * THANK YOU!!

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [thenameisnick](https://wordpress.org/support/users/thenameisnick/)
 * (@thenameisnick)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/need-code-help-creating-conditional-archive-template-1/#post-1211402)
 * This is a double post. I answered it here:
    [http://wordpress.org/support/topic/310646?replies=2](http://wordpress.org/support/topic/310646?replies=2)
 *  Thread Starter [wildbug](https://wordpress.org/support/users/wildbug/)
 * (@wildbug)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/need-code-help-creating-conditional-archive-template-1/#post-1211551)
 * Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘need code help creating conditional archive template’ is closed to new
replies.

 * 2 replies
 * 2 participants
 * Last reply from: [wildbug](https://wordpress.org/support/users/wildbug/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/need-code-help-creating-conditional-archive-template-1/#post-1211551)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
