• Resolved flicker07

    (@flicker07)


    hello to all,
    how can i add condition on this code:

    <div class="single-specials">Special 1</div>
    <div class="info">
    			<ul>
    <li class="sm-name-info"><strong>Name: </strong> <?php echo do_shortcode('[ecpt_field id="name"]'); ?></li>				
    
    <li class="sm-image-info"><img src="<?php echo get_post_meta($post->ID, 'ecpt_image', true); ?>" alt=""/><!--<img src="/wp-content/themes/twentyeleven/images/dummy-img.jpg" />--></li>			
    
    <li class="sm-desc-info"><strong>Description: </strong><?php echo do_shortcode('[ecpt_field id="description"]'); ?></li>				
    
    <div class="clear"></div>
    			</ul>
    </div>

    i would like to add condition that will hide the whole div/ class=”single-special” if all fields name, description and image is empty. However if one of the fields has a value say for example name, only name will display and so on. so it will look something like this:


    Specials 1
    Name: Sample name;

    i know i should use php code, if else but i’m not good at it. so if anybody knows how, please help me. thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Have a try with this:

    <div class="single-specials">Special 1</div>
    <div class="info">
      <ul>
        <?php if ( get_post_meta($post->ID, 'name', true) ) { ?>
          <li class="sm-name-info"><strong>Name: </strong> <?php echo do_shortcode('[ecpt_field id="name"]'); ?></li>
        <?php  } ?>
    
        <?php if ( get_post_meta($post->ID, 'ecpt_image', true) ) { ?>
          <li class="sm-image-info"><img src="<?php echo get_post_meta($post->ID, 'ecpt_image', true); ?>" alt=""/><!--<img src="/wp-content/themes/twentyeleven/images/dummy-img.jpg" />--></li>
        <?php  } ?>  
    
        <?php if ( get_post_meta($post->ID, 'description', true) ) { ?>
          <li class="sm-desc-info"><strong>Description: </strong><?php echo do_shortcode('[ecpt_field id="description"]'); ?></li>
        <?php  } ?> 
    
        <div class="clear"></div>
      </ul>
    </div>

    Hope that works for you, well there might be a nicer solution for it, instead of 3x if conditions, but lets have a try if it works with your ecpt_field id="description"

    //EDIT
    But that does not hide the entiry div, if they are all empty!

    Okok… Version 0.2 ??
    This should hide the entire div, if your outputs are empty…

    https://pastebin.com/g6Cu4aGP

    Let me know ??

    Thread Starter flicker07

    (@flicker07)

    thanks a lot sir for your reply. i already figured out ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘adding of conditions on the template file’ is closed to new replies.