Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WP高级自定义字段数组if语句错误_Php_Wordpress_Advanced Custom Fields - Fatal编程技术网

Php WP高级自定义字段数组if语句错误

Php WP高级自定义字段数组if语句错误,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我用它在Wordpress中通过高级自定义字段拉入一个条件值: <?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

我用它在Wordpress中通过高级自定义字段拉入一个条件值:

    <?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 -->;' ?>

“alt=”“/>
但是我收到了这个错误:PHP解析错误:语法错误,意外的“(”在/nas/wp/www/cluster-3024/omniaagency/wp content/themes/omniaagency/page-case-study-single.PHP的第29行,参考:

我不确定我做错了什么


有人知道我如何解决这个问题吗?

我格式化了你的代码,并重写了一些语法;你有一堆不必要的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();
        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 -->';
if(在_数组('Branding',get_字段('services_provided'))中){
回显'Branding'。获取_字段('services_text_Branding');
如果(有行('branding\u images\u repeater')):
while(have_rows('branding_images_repeater')):the_row();
如果(获取子字段(“品牌图片”):
?>
“alt=”“/>

谢谢jaunveliz!你帮我弄明白了。你把最后一个括号放错地方了。把编辑过的代码贴在下面

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 -->'};
if(在_数组('Branding',get_字段('services_provided'))中){
回显'Branding'。获取_字段('services_text_Branding');
如果(有行('branding\u images\u repeater')):
while(have_rows('branding_images_repeater')):the_row();
如果(获取子字段(“品牌图片”):
?>
“alt=”“/>

我会把它清理到,else:endif;有点毫无意义,事实上整个外部if是不需要的,因为while()期望函数为true,如果为false,则跳过循环,因此我会丢弃整个外部if。谢谢你的建议。我现在在我的错误日志中得到它:[Sat Nov 08 02:15:52 2014][error][client 72.192.63.54]PHP解析错误:语法错误,在第37行的/nas/wp/www/cluster-3024/omniaagency/wp content/themes/omniaagency/page-case-study-single.PHP中出现意外“}”,请参考:
“alt=”“/>