WordPress.org

Ready to get started?Download WordPress

Forums

How do I implement conditions for elements? (5 posts)

  1. C05T1N
    Member
    Posted 4 years ago #

    Hey there,

    I've just started working on a new wordpress theme and I would like to include, next to each post, a category icon.
    The problem is that i don't know exactly how to state the conditions (for example, all articles under the category 1 should have a big 1 logo for an icon, and so on for the next ones).

    Can you please help me?

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    And what if a post is in more than 1 category?

  3. C05T1N
    Member
    Posted 4 years ago #

    Then I'll assign an icon that corresponds to "multiple categories".

    Do you know the solution to my problem?

  4. esmi
    Forum Moderator
    Posted 4 years ago #

    <?php if(in_category('1')) $cat_image = cat1.gif;
    elseif(in_category('2')) $cat_image = cat2.gif;
    [...]
    else $cat_image = multi-cat.gif;?>

    It's a bit clumsy, though, and could be difficult to maintain.

  5. C05T1N
    Member
    Posted 4 years ago #

    Thanks, i'll give this a go as soon as possible.

Topic Closed

This topic has been closed to new replies.

About this Topic