Forums

[resolved] php if in wordpress (6 posts)

  1. emiliss
    Member
    Posted 2 years ago #

    Hi.

    I need to make a php if command (at least I think so), which first checks if the post in is a certain category. I guess in_category(); would do this.

    Then, if that's true, it should check if the browser is IE7 or older, and if it is, print some text. I found a solution for that already:

    <!--[if lte IE 7]>
    <div>
    Displayed in IE 7 and lesser version of IE on IE 6 , IE 5 etc.
    </div>
    <![endif]-->

    How do I connect these to, or is it possible? I'm really new to php.

    Thanks for your answer.

  2. Robert Chapin (miqrogroove)
    Member
    Posted 2 years ago #

    <?php if (in_category( 42 )) { ?>
    <!--[if lte IE 7]>
    <div>
    Displayed in IE 7 and lesser version of IE on IE 6 , IE 5 etc.
    </div>
    <![endif]-->
    <?php } ?>

    ... where 42 is the category ID number.

  3. stvwlf
    Member
    Posted 2 years ago #

    wrap your IE7 code in a IF PHP statement so its only included when the PHP conditions you specify are true. In this code, the test to see if this is IE7 or less won't even appear in the HTML if the post is not in category 7

    <?php if ( in_category(7) ) { ?>
    <!--[if lte IE 7]>
    <div>
    Displayed in IE 7 and lesser version of IE on IE 6 , IE 5 etc.
    </div>
    <![endif]-->
    <?php } ?>
  4. emiliss
    Member
    Posted 2 years ago #

    Hi again, thanks for your answers.

    This still doesn't seem to work, I'm trying to use it in archive page template, but is that a wrong place to do so?

  5. emiliss
    Member
    Posted 2 years ago #

    Correction: I'm using it in archive.php, since I have pages where I want to show posts from a single category, and in one of those categories I would like to add the above code in each post.

  6. emiliss
    Member
    Posted 2 years ago #

    Ah, silly me. I had a wrog cat ID. Silly me.

    Thanks guys!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.