Forums

[resolved] Calling All Wordpress Masters - if statements (3 posts)

  1. mrsheedy
    Member
    Posted 3 years ago #

    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.

  2. ifelse
    Moderator
    Posted 3 years ago #

    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.

  3. mrsheedy
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic