• hi,

    I am using Custom Field Suite and my piece of code works fine, it shows a banner and some text on my web pages, I woudl like to write an IF statement around this to say: IF there is no banner or text THEN use default

    here is my working code:

    <img src="<?php echo $cfs->get('banner_image'); ?>" width="960" height="212" alt="banner3">
    								<div class="staticbannertext">
    								<h3><?php echo $cfs->get('banner_text_small'); ?></h3>
    								<span><?php echo $cfs->get('banner_text_big'); ?></span>

    here is my attempt at the IF statement:

    <?php if query_posts('meta_key=banner_feature&meta_value=Yes'); ?>
    								<img src="<?php echo $cfs->get('banner_image'); ?>" width="960" height="212" alt="banner3">
    								<div class="staticbannertext">
    								<h3><?php echo $cfs->get('banner_text_small'); ?></h3>
    								<span><?php echo $cfs->get('banner_text_big'); ?></span>
    							<?php else; ?>
    								<img src="../wp-content/themes/corniche/images/banner3.png" width="960" height="212" alt="banner3">
    								<div class="staticbannertext">
    								<h3>text</h3>
    								<span>text</span>
    							<?php endif; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    if this is inside the loop you can try it with this [untested]:

    <?php
    $feature = get_post_meta($post->ID, 'banner_feature', true);
    if($feature == 'Yes') :
    ?>
    <!-- rest of code -->
    <?php else : ?>
    <!-- rest of code -->
    <?php endif; ?>

    Thread Starter jbiddulph

    (@jbiddulph)

    Thanks!
    About 15 minutes before you replied, I found this:

    <?php $image=get_post_meta($post->ID, 'banner_image', true); ?>
    							<?php if ( $image ) : ?>
    								<img src="<?php echo $cfs->get('banner_image'); ?>" width="960" height="212" alt="banner3">
    								<div class="staticbannertext">
    								<h3><?php echo $cfs->get('banner_text_small'); ?></h3>
    								<span><?php echo $cfs->get('banner_text_big'); ?></span>
    							<?php else : ?>
    								<img src="/wp-content/themes/corniche/images/banner3.png" width="960" height="212" alt="banner3">
    								<div class="staticbannertext">
    								<h3>text</h3>
    								<span>text</span>
    							<?php endif; ?>

    Very similar… Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘using Custom Field Suite – need to write an IF statement’ is closed to new replies.