Forums

Using category.php instead of multiple category-#.php's? (1 post)

  1. AquaM
    Member
    Posted 6 months ago #

    In an attempt to set up my wordpress the way I want, I've been trying to do two things: Show a list of Subcategories in Categories that have those and not show posts; and in stand-alone Categories with posts and Subcategories with posts, show the post as it is displayed on the index instead of a link to the post.

    I've actually somehow managed to get it to do these two things (I haven't learned php but I can often fumble my way around and figure stuff out).. But I'm having to use the category-#.php method. I was wondering if there's a simpler way I could do it in just a category.php file? I tried using if statements but while the first three worked (the category with subcategories), all the other categories used the final else statement.. I'm sure I messed something up.

    This is basically what I was trying:

    <?php if (is_category('22')) { ?>
    --Category with Subcategories here. Was making them show as a list of subcategories--
    <?php } elseif (is_category('23')) { ?>
    --Subcategory with index style posts--
    <?php } elseif (is_category('28')) { ?>
    --Subcategory with index style posts--
    <?php } elseif (is_category('19')) { ?>
    --Category with index style posts--
    <?php } elseif (is_category('20')) { ?>
    --Category with index style posts--
    <?php } else { ?>
    --If everything else failed there was text here so far.--
    <?php } ?>

    And so on.. It fails after category 23. Any suggestions? I could do it the longer way, but it's a lot faster if I could do it in one file.

Reply

You must log in to post.

About this Topic