• Referring to the Codex guide on category templates, I’ve found out how to display different text according to which category a visitor is looking at.

    <?php if (is_category('Category A')) { ?>
    <p>This is the text to describe category A</p>
    <?php } elseif (is_category('Category B')) { ?>
    <p>This is the text to describe category B</p>
    <?php } else { ?>
    <p>This is some generic text to describe all other category pages,
    I could be left blank</p>
    <?php } ?>

    What I’d like to know is, is it possible to shorten this code, as I have around 35 different categories to do this for! If those category IDs run from, say, 10-45, is there a way to ‘loop’ it, rather than repeat the code by hand coding it?

  • The topic ‘Shortening code for category-X.php’ is closed to new replies.