Different categories templates in index.php
-
Hi everyone.
I want to make a diferent template for each of my categories, but I don?′t want to use one php file per category, because I have 57 categories.
My index.php looks like this:
<?php get_header(); ?>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" align="center" valign="top"><?php include(TEMPLATEPATH . '/basepost.php'); ?></td>
<td align="center" width="189" valign="top"><?php include(TEMPLATEPATH . '/sidebar.php'); ?></td>
</tr>
</table>
<?php get_footer(); ?>And my “blog” category, with ID 5, is that:
<?php get_header(); ?>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" align="center" valign="top"><div class="blogtitle"></div><?php include(TEMPLATEPATH . '/basepost.php'); ?></td>
<td align="center" width="189" valign="top"><?php include(TEMPLATEPATH . '/sidebar-blog.php'); ?></td>
</tr>
</table>
<?php get_footer(); ?>(note that basepost.php is the WP loop in a diferent php file, for easy handle)
I try to make that to show only in the index these two templates:
<?php get_header(); ?>
<?php if ( is_category('5') ) : ?>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" align="center" valign="top"><div class="blogtitle"></div><?php include(TEMPLATEPATH . '/basepost.php'); ?></td>
<td align="center" width="189" valign="top"><?php include(TEMPLATEPATH . '/sidebar-blog.php'); ?></td>
</tr>
</table>
<?php } else { // Do stuff specific to non-first page ?>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" align="center" valign="top"><?php include(TEMPLATEPATH . '/basepost.php'); ?></td>
<td align="center" width="189" valign="top"><?php include(TEMPLATEPATH . '/sidebar.php'); ?></td>
</tr>
</table>
<?php endif; ?>
<?php get_footer(); ?>But that doesn?′t work. I don?′t know what I doing wrong. I?′ve searched the codex for hours searching a way to fix that, but I don?′t found anything. How can I make that to work fine, and how can I make that for more categories, not only for one? Remember I don?′t want use categories php files.
Thanks for your time people ^^.
- The topic ‘Different categories templates in index.php’ is closed to new replies.