problem with loop

时间:2016-11-02 作者:Rafal

我对这段代码有问题,每当我在它后面放东西时,它就会中断。查询是否正确关闭?

  <div class="container">
<div class="col-sm-12 col-xs-12">
<div class="headdark"><h3>Places nearby <?php echo the_title()?> </h3></div>
<div class="condark relbeach bearound row">

$loclat = get_post_meta($post->ID, \'map_lat\', true);
$loclng = get_post_meta($post->ID, \'map_lng\', true);
$posttype = \'location\';
$dist = 10;
$nearbyLocation = get_nearby_loc($loclat, $loclng, $posttype, $dist);
 if ($nearbyLocation):
 global $post;
foreach ($nearbyLocation as $post): 
setup_postdata($post); ?>

<div class="col-md-3">
<div class="aroundbeach">
<?php 

if((round($post->distance,4) * 1000) > 1000) {
    echo \'<div class="distt">\'.round($post->distance,2).\' KM away\'.\'</div>\';
}else{
 echo \'<div class="distt">\'.(round($post->distance,2) * 1000).\' M away\'.\'</div>\';
}
?></div><div class="thumb">
       <header class="thumb-header"><a href="<?php the_permalink(get_the_ID()) ?>" class="hover-img">
                <?php
                   $img = get_the_post_thumbnail( get_the_ID() , array(360,270,\'bfi_thumb\'=>true)) ;
                   if(!empty($img)){
                       echo balanceTags($img);
                   }else{
                       echo \'<img width="360" height="270" alt="no-image" class="wp-post-image" src="\'.bfi_thumb(get_template_directory_uri().\'/img/no-image.png\',array(\'width\'=>360,\'height\'=>270)) .\'">\';
                   }
                   ?>
</a></header>
        <div class="thumb-caption">
            <h5 itemprop="name" class="thumb-title"><a class="text-darken" href="<?php the_permalink() ?>"><?php the_title();?></a></h5>
<div class="text-darken"></div>
            <p class="mb0 text-darken">
            </p></div></div></div>
 <?php endforeach; ?>
 <?php else : ?>
    <h3 class="center">It seems like there are no places around</h3>
 <?php endif;  ?>
</div></div></div>

1 个回复
最合适的回答,由SO网友:Kanon Chowdhury 整理而成

我认为您在流动代码中缺少分号。我添加了分号。

    <div class="headdark"><h3>Places nearby <?php echo the_title();?> </h3></div>


<header class="thumb-header"><a href="<?php the_permalink(get_the_ID()); ?>" class="hover-img">



<div class="thumb-caption">
            <h5 itemprop="name" class="thumb-title"><a class="text-darken" href="<?php the_permalink() ;?>"><?php the_title();?></a></h5>
以及

您已使用{} 但在流动代码中,在结束逻辑中使用**:*

<?php else : ?
    <h3 class="center">It seems like there are no places around</h3>
 <?php endif;  ?>