• Resolved madcore

    (@madcore)


    I want to put inside category.php a different template for each category I have in my WP, instead of having a category-#.php for each one. But I was reading in the codex the Custom Category Templates page, and I don?′t understand too much on that page.

    I don?′t think that?′s is the correct way:

    <?php if ( is_category('1') ) : ?>
    [template code here]
    <?php endif; ?>
    <?php if ( is_category('2') ) : ?>
    [template code here]
    <?php endif; ?>
    <?php if ( is_category('3') ) : ?>
    [template code here]
    <?php endif; ?>...[/code]

    Someone can help to make it work in a proper way?

Viewing 4 replies - 1 through 4 (of 4 total)
  • There is a good article on what you’re attempting to do at camera on the road.

    Lorelle explains how to code the category stuff into your existing category.php for different category templates

    Thread Starter madcore

    (@madcore)

    I?′ve read that page, and a find some examples of things looks nearly like that I want, but not exactly. Following some things i?′ve readed in that page, I try this in my category.php:

    <?php get_header(); ?>
    <?php if ( in_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; ?>
    <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(); ?>

    That doesn?′t work. And I don?′t know how to make it.

    Aren’t you missing some “{” and “}” brackets from that code? I am not a coder but looking at the examples provided here Conditional_Tags it seems to me they are missing…

    Thread Starter madcore

    (@madcore)

    Finally, I did it ^^.

    I used the php switch function, and the internal $cat wp variable to make it work. Look at the code:

    <?php get_header(); ?>
    <?php
    switch ($cat) {
    //BLOG
    case 5:
    case 46:
    case 58:
    case 26:
    case 56:
    case 48:
    case 49:
    case 57:
    case 52:
    case 27:
    case 51:
    case 28:
    case 44:
    case 24:
    case 29:
    case 25:
    case 43:
    case 47:
    case 50:
    echo '<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td width="100%" align="center" valign="top"><div class="blogtitle"></div>';
    include(TEMPLATEPATH . '/basepost.php');
    echo '</td><td align="center" width="189" valign="top">';
    include(TEMPLATEPATH . '/sidebar-blog.php');
    echo '</td></tr></table>';
    break;
    default:
    echo '<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td width="100%" align="center" valign="top"></div>';
    include(TEMPLATEPATH . '/basepost.php');
    echo '</td><td align="center" width="189" valign="top">';
    include(TEMPLATEPATH . '/sidebar.php');
    echo '</td></tr></table>';
    }
    ?>
    <?php get_footer(); ?>

    With that, all the categories on the case tags under the blog commented line uses the template under them. After the break; line, al the another categories not matching any of the case uses the template under the default. Greatly easy way to do that I want.

    Thanks to all for your help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Help with <?php if ( is_category() ) : ?> function’ is closed to new replies.