1

I'm using this to pull in a conditional value in Wordpress with advanced custom fields:

    <?php if( in_array( 'Branding', get_field('services_provided') ) ) {
    echo '<div class="branding"><div class="text"><h2>Branding</h2>' . get_field('services_text_branding') . '</div>';
    if( have_rows('branding_images_repeater') ):                                 
        while ( have_rows('branding_images_repeater') ) : the_row();
        ?>
            <?php if (get_sub_field('branding_images')): ?>
            <img src="<?php echo the_sub_field('branding_images'); ?>" alt="" />
            <?php endif; ?>
        <?php endwhile; else : endif; } ?>
     <?php echo '</div> <!--end branding -->;' ?>

However I am receiving this error: PHP Parse error: syntax error, unexpected '(' in /nas/wp/www/cluster-3024/omniaagency/wp-content/themes/omniaagency/page-case-study-single.php on line 29, referer: http://www.mydomainname.com/

And I am unsure what I am doing wrong.

Does anyone one know how I can fix this?

2 Answers2

0

I formatted your code, and rewrote some of the syntax; you have a bunch of php tags that aren't necessary. Plus, you have a semi-colon on your last statement inside of a string that isn't needed:

if(in_array('Branding', get_field('services_provided'))){
    echo '<div class="branding"><div class="text"><h2>Branding</h2>' . get_field('services_text_branding') . '</div>';
    if(have_rows('branding_images_repeater')):
    while(have_rows('branding_images_repeater')) : the_row();
        if(get_sub_field('branding_images')):
        ?>
        <img src="<?php echo the_sub_field('branding_images'); ?>" alt="" />
        <?php
        endif;
    endwhile;
    else : endif;
}
echo '</div> <!--end branding -->';

So try that, I think that will yield you favorably.

visigoth
  • 208
  • 1
  • 8
  • I'd clean this up to, else : endif; somewhat pointless, in fact the whole outer if is unneeded because of while ( ) expects true from the function and if it's false, the loop is skipped over, so I'd toss the whole outer if. – ArtisticPhoenix Nov 08 '14 at 02:06
  • Thanks for the suggestion. I am now getting this in my error logs: [Sat Nov 08 02:15:52 2014] [error] [client 72.192.63.54] PHP Parse error: syntax error, unexpected '}' in /nas/wp/www/cluster-3024/omniaagency/wp-content/themes/omniaagency/page-case-study-single.php on line 37, referer: http://omniaagency.wpengine.com/ – theomniaagency Nov 08 '14 at 02:56
  • `

    Branding

    ' . get_field('services_text_branding') . '
    '; if(have_rows('branding_images_repeater')): while(have_rows('branding_images_repeater')) : the_row(); if(get_sub_field('branding_images')): ?> '; ?> `
    – theomniaagency Nov 08 '14 at 03:06
0

Thanks jaunveliz! You helped me figure it out. You had the last bracket in the wrong spot. Posting the edited code below.

if(in_array('Branding', get_field('services_provided'))){
echo '<div class="branding"><div class="text"><h2>Branding</h2>' . get_field('services_text_branding') . '</div>';
if(have_rows('branding_images_repeater')):
while(have_rows('branding_images_repeater')) : the_row();
    if(get_sub_field('branding_images')):
    ?>
    <img src="<?php echo the_sub_field('branding_images'); ?>" alt="" />
    <?php
    endif;
endwhile;
else : endif;

echo '</div> <!--end branding -->'};