Forums

[resolved] Help with if then else statement (3 posts)

  1. johnnyspade
    Member
    Posted 3 weeks ago #

    Hello,

    I have a website that pulls in a different bit of content for each page and I have been using a custom field with this code:

    <?php if(get_post_meta($post->ID, "quote", true)); ?>
    <div id="rhtquote"><?php echo get_post_meta($post->ID, "quote", true); ?></div>
    <?php ?>

    The problem I am having however is that the rhtquote div id pulls in a background image and this div persists even if there if no "quote" custom field set up for that page, obviously.

    How can I code this so that if there isn't a custom field added for the page then nothing is added, including those div tags?

    Much thanks,
    Brandon

  2. kkarpieszuk
    Member
    Posted 3 weeks ago #

    code is not correct

    in first line change ; into : (now you just finish if statement without pulling any codde after that)

    second line is ok. but because in first line you closed if statement with ; it is just regular code, not depended on if statement. so this divs appear always

    in last line change
    <?php ?>
    into if-statement-closing-tag:
    <?php endif; ?>

  3. johnnyspade
    Member
    Posted 2 weeks ago #

    That works like a charm, thanks.

Reply

You must log in to post.

About this Topic