Php 我的代码导致无限循环,可以';我看不到虫子
我正在使用高级自定义字段插件进行WordPress项目 然而,我从我的代码中得到了一个疯狂的无限循环,所以我显然在某个地方把事情搞砸了,然而,经过两个小时的研究,我看不出问题所在Php 我的代码导致无限循环,可以';我看不到虫子,php,wordpress,custom-fields,Php,Wordpress,Custom Fields,我正在使用高级自定义字段插件进行WordPress项目 然而,我从我的代码中得到了一个疯狂的无限循环,所以我显然在某个地方把事情搞砸了,然而,经过两个小时的研究,我看不出问题所在 <?php get_header(); ?> <?php // If the loop has posts if (have_posts()) : // For each post this page has while (have_posts
<?php get_header(); ?>
<?php
// If the loop has posts
if (have_posts()) :
// For each post this page has
while (have_posts()) : the_post();
// Display the Flexible Content
while(has_sub_field('add_row')):
// If the content type is Tagline
if(get_row_layout() == 'tagline'): ?>
<div class="row paddingBottom paddingTop">
<div class="col-xs-12">
<h3 class="tagLine"><?php the_sub_field('tagline'); ?></h3>
</div>
</div>
<?php
// If the content type is a Featured Image
/*elseif ( get_row_layout() == 'featured_image' ): ?>
<div class="col-xs-12 textCenter">
<?php
$attachment_id = get_sub_field('featured_image');
$size = "full-width"; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );
?>
<img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" />
</div>
<?php*/
// If the content type is a horizontal rule
elseif ( get_row_layout() == 'horizontal_rule' ) : ?>
<div class="row">
<div class="col-xs-12">
<hr />
</div>
</div>
<?php
// If the content type is Columns
elseif ( get_row_layout() == 'columns' ):
// If there is at least one column section
if(get_sub_field('column')):
// For each column section
while(has_sub_field('column')): ?>
<div class="row paddingTop paddingBottom">
<?php
if(get_sub_field('column_content_type')):
$count_rows = 0;
// Counting
while(has_sub_field('column_content_type')):
$count_rows++;
endwhile;
// Loop
while(has_sub_field('column_content_type')): ?>
<div class="
<?php /*
if ( $count_rows == 1 ) :
echo "col-xs-12";
elseif ( $count_rows == 2 ) :
echo "col-xs-6";
elseif ( $count_rows == 3 ) :
echo "col-xs-6 col-sm-4";
elseif ( $count_rows == 4 ) :
echo "col-xs-6 col-sm-6 col-md-4";
endif; */
?>
"> <?php
// Title
if ( get_sub_field('title') ) : ?>
<h2 class="smallTitle"><?php the_sub_field('title');?></h2><?php
endif;
// Text Area
if ( get_sub_field('text') ) :
the_sub_field('text');
endif;
// Link
if ( get_sub_field('link') ) : ?>
<?php // eventually need to make it so you can change the link text ?>
<a class="textCenter" href="<?php the_sub_field('link'); ?>">
More info
</a> <?php
endif; ?>
</div> <?php
endwhile;
endif;
?>
</div>
<?php
endwhile; // end for each column section
endif; // end checking for at least one column section
endif; // end checking content type is columns
endwhile; // end flexible content
endwhile; // end for each post
endif; // end checking for at least one post
?>
<?php get_footer(); ?>
“alt=”“/>
我认为错误是
//显示灵活的内容
while(有子字段(“添加行”):
我认为您需要使用if(){
//代码
}
而不是“while”
这是你的问题…但根据我所看到的,这可能是许多问题之一。看起来你认为while循环就像if语句一样工作…你在循环中所做的一切都是不断地增加它。它永远不会结束。while(has_sub_字段('column_content_type')是否会while(has_sub_字段('column_content_type'))
循环是否终止?你只是在循环中增加一个变量。第87行有一个endwhile来结束它…你知道While循环是如何工作的吗?我想你可以用endwhile来结束While语句,就像if语句一样。如果你想退出循环,你可以使用break;
我试过了,但没有用。我使用了代码根据你的建议,但无限循环仍然存在。我还发现了这个链接,它建议使用has_sub_field()advancedcustomfields.com/resources/field-types/flexible-contentAh对,我觉得你可以用endwhile结束while语句,正如文档()如何最好地结束这个while语句?为什么还要在while循环中呢?它已经在一个嵌套循环中了。我完全困惑了,很抱歉我是一个noob,我不知道怎么做。我们在某个时候都是新的,不用担心。我自己对整个PHP还是有点陌生。但是请稍等一下。我发现了一些问题。我将编辑我的ans请稍候。我真的不知道从哪里开始。您的大多数循环都不会结束。它不会增加或更改任何值,从而导致错误。您从何处获得此代码?我真诚地建议在进一步操作之前先学习一些PHP。不要粗鲁。
while(has_sub_field('column_content_type')):
$count_rows++;
endwhile;