• Resolved mrsheedy

    (@mrsheedy)


    Hello

    I’ve tried posting a few times about this now as well as bashing my head against a wall and I’m still getting absolutely nowhere.
    Can you have the style of a post vary depending on the posts custom value entered in the custom field. Like this:

    If the custom value is “front” output this HTML…
    or else…
    If the custom value is “back” output this HTML…

    I would ask if this can even be done but given the rest of the things that you can do with wordpress I’m sure it can. I’m not a programmer but it really doesn’t seem all that complicated.

    Does anyone have any suggestions. Even just some pointers on using an if statement properly and retrieving a custom field’s value would give me something to work with.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Just use something like the following in The_Loop:
    <?php
    //get custom value
    $custom_option = get_post_meta($post->ID, 'your_custom_field', true);
    //if conditions
    if ($custom_option == 'SOME_VALUE'){
    ?>
    <!-- HTML STUFF -->
    <?php } else { ?>
    <!-- Alternative HTML STUFF -->
    <?php } ?>

    I use a simple form of this for changing the ‘add a comment’ text.

    Thread Starter mrsheedy

    (@mrsheedy)

    Mate you are a LEGEND!
    Works like a charm. Thank you so much.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Calling All WordPress Masters – if statements’ is closed to new replies.