WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] echo conditional tag depending on conditional tag?

[Resolved] echo conditional tag depending on conditional tag?

  • Is it possible to echo php code, depending which page you are on. I do not want to echo a whole block of text but only a conditional tag which is wrapped around my loop.
    This is the conditional tag that I want to print, but only, if I am on the home page:
    <?php if (!(in_category(‘6’)) ) { ?>THE LOOP<?php } ?>
    How do I do this? Do I simply put my conditional tag in an if statement like so:
    if (is_home()) {
    echo “if (!(in_category(‘6’)) ) {“;
    }THE LOOP
    if (is_home()) {
    echo “}”;
    }

    Or do I have to do it another way?
    Thanks dl33

Viewing 6 replies - 1 through 6 (of 6 total)
  • <?php if ( is_home() && !in_category('6') ) { ?>

    THE LOOP CONTENT

    <?php } ?>

    Yup, I thought about that, but if the page is not home, then the loop will not be gone through. Yet I also want the loop to show if the page is not home. The loop should only be wrapped in the !in_category(‘6’) conditional if I am on the home page, otherwise not. With the above solution the loop wouldn’t display it at all on those other pages.
    dl33


    <?php if ( ((is_home()) AND (in_category('6'))) OR (!is_home()) ) { ?>

    THE LOOP CONTENT

    <?php } ?>

    …I think. It took me a while to work those brackets out. My brain hurts.

    Slightly easier to read version of karrde’s:

    <?php if ( (is_home() && in_category('6')) || !is_home() ) { ?>

    A little crazy with the parens :). And to iterate through the if statement in plain language: If we're on the home page but in category 6, *or* not on the home page at all.

    Yeah, I had to re-edit the post a couple of times cus those parens confused the bejeezus out of me.

    The order is important though, for precedence’s sake.

    Thanks a lot… This saves me multiple loops and else statements. In the end I actually used this though:
    <?php if ( (is_home() && !in_category('6')) || !is_home() ) { ?>
    It works perfect…(although the brackets are making me dizy as well;-)

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] echo conditional tag depending on conditional tag?’ is closed to new replies.