profile counter myspace
Website Design and Development | WordPress Development
Call Us Free: 1-877-792-0328

ACF with Conditional Statements

I really like ACF (Advanced Custom Fields).  On a project that I work as a subcontractor a request for a testimonial to display on the right side of the primary content, but only display if there is a testimonial for that Page (which is actually a custom post type using My Content Management).

 


<?php // if the field "name" is blank do not display testimonial ?>
 <?php if(get_field('name')!= '') { ?>
 <div id="testimonial">
 <div class="name"><?php the_field('name'); ?></div>
 <div class="title"><?php the_field('title'); ?></div>
 <div class="theimage"><?php
 $image = get_field('photo');
 if( !empty($image) ): ?>
 <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
 <?php endif; ?></div>
 <div class="quote"><?php the_field('testimonial'); ?></div>
 </div><!-- / end testimonial -->
 <?php } ?>

 


/* for testimonials */
#testimonial {margin: 10px 0 10px 10px; float: right;background-color: #d51820; color: #ffffff;width: 240px;  font-family: Trocchi, serif !important;font-size: 14px;}
#testimonial .name {margin-top: 20px;text-align: center;font-weight: bold;}
#testimonial .title {text-align: center; font-style: italic;}
#testimonial .theimage {width: 176px; margin: 0 auto;}
#testimonial .quote {margin: 10px 15px;}
/* end for testimonials */

This is what the client wanted it to look like and it does, and on the Pages were there is not a testimonial the red box doesn’t display, and the content goes full-width.

Click to enlarge

Click to enlarge

Leave a Reply

WordPress Code Tidbits

Marketing

News & More