• Resolved threevisual

    (@threevisual)


    I’m not too good with PHP… can someone please tell me what I’ve done wrong with the following as it’s returning an error to me and I can’t figure it out….

    <?php if (in_category('8')) {echo '<strong>Select your rating:</strong> <?php if(function_exists('the_ratings')) { the_ratings(); }?> ';} ?>

    Thanks

    Edit: the error being returned is:

    Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’ in /home/wired/public_html/wp-content/themes/wired/comments.php on line 90

Viewing 6 replies - 1 through 6 (of 6 total)
  • I think you are missing the second part:
    if in category 8 – do something
    else – do somehting other or nothing

    Read about the usage of Conditional Tags on WordPress codex.

    Thread Starter threevisual

    (@threevisual)

    thanks evita… although i’m still a little confused on how to add the else tag, it’s still throwing the error at me. I really should try and learn the basics of PHP.

    Maybe this will help you:

    <?php if ( in_category(xx) ) { ?>
    DO SOMETHING
    <?php } else { ?>
    DO SOMETHING OTHER OR LEAVE IT BLANK
    <?php } ?>
    Thread Starter threevisual

    (@threevisual)

    excellent! thank you!
    I think I have it now, have no idea what I was doing before but it wasn’t working.

    Thread Starter threevisual

    (@threevisual)

    Is there anyway to modify this so its if in SUB category of x?

    Thread Starter threevisual

    (@threevisual)

    OK, I’ve had a look around and found that in_category doesn’t pick up sub-categories so you have to list them manually. For anyone else trying to do something similar here’s how you do it:

    <?php if ( in_category(2) || in_category (2) || in_category (3) || in_category (4) ) { ?>
    Content
    <?php } else { ?>
    Content
    <?php } ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Whats wrong with this code?’ is closed to new replies.