Forums

[resolved] Whats wrong with this code? (7 posts)

  1. ThreeVisual
    Member
    Posted 3 years ago #

    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

  2. Evita
    Member
    Posted 3 years ago #

    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.

  3. ThreeVisual
    Member
    Posted 3 years ago #

    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.

  4. Evita
    Member
    Posted 3 years ago #

    Maybe this will help you:

    <?php if ( in_category(xx) ) { ?>
    DO SOMETHING
    <?php } else { ?>
    DO SOMETHING OTHER OR LEAVE IT BLANK
    <?php } ?>
  5. ThreeVisual
    Member
    Posted 3 years ago #

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

  6. ThreeVisual
    Member
    Posted 3 years ago #

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

  7. ThreeVisual
    Member
    Posted 3 years ago #

    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 } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.