0

This is from the codex:

<?php if ( get_post_meta($post->ID, 'thumb', true) ) : ?>
    <a href="<?php the_permalink() ?>" rel="bookmark">
        <img class="thumb" src="<?php echo get_post_meta($post->ID, 'thumb', true) ?>" alt="<?php the_title(); ?>" />
    </a>
<?php endif; ?>

I want to include an if statement like the example above. But I can't figure out the proper way of doing that to the following:

<?php // Set and display custom field
        $mainbar_left_title = get_post_meta($post->ID, 'Mainbar Left Title', true);
        $mainbar_left_image = get_post_meta($post->ID, 'Mainbar Left Image', true); ?>
        <div class="float-left">
            <h2><?php echo $mainbar_left_title; ?></h2>
            <img src="<?php echo $mainbar_left_image ?>" alt="" />
        </div> <?php
    ?>
5

<?php if ( $mainbar_left_title && $mainbar_left_image ) : ?>

See http://www.php.net/manual/en/language.operators.logical.php

2

<?php if ( get_post_meta($post->ID, 'Mainbar Left Title', true) && get_post_meta($post->ID, 'Mainbar Left Image', true) ) ) : ?>
        <div class="float-left">
        <h2><?php echo $mainbar_left_title; ?>
            <img src="" alt="" />
        </div>
<?php endif; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.