Forums

[resolved] if (is_category('34,35,36,37,38')) show text "This is category" (4 posts)

  1. dilana
    Member
    Posted 2 years ago #

    I have tried 3543657 to do this in the post, but with no succes.

    <?php if (is_category('34')) { ?>
    <p>This is category 34</p>
    <?php } ?>

    I want when i open some post in category ID 34,35,36 or 37 or 38 to show somewhere in the post the text "This is category"

    Thanx in advance ;)

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    You need a plugin to put code in a post so look at http://wordpress.org/extend/plugins/exec-php/

    And if you are wanting to know of a post being in a particular category use the in_category().

    The loop article has an example.

  3. dilana
    Member
    Posted 2 years ago #

    I put this code in single.php in the loop... and is not working...

    i tried also this:

    <?php if (is_category('1')) { ?>
    <p>This is category 1</p>
    <?php }else { ?>
    <?php } ?>

    and this:

    <?php if (is_category('1')) : ?>
    <p>This is category 1</p>
    <?php }else : ?>
    <?php : ?>

    and this:

    <?php if( is_category('3, 14, 55, 11') ) echo 'Hello';
    elseif echo 'Goodbye';?>

    but no one of them works....

  4. dilana
    Member
    Posted 2 years ago #

    It works! Thank you :)
    I tried this

    <?php if (in_category('1')) { ?>
    <p>This is category 1</p>
    <?php }else { ?>
    <?php } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic