更改if格式是否会导致"解析错误:语法错误,unexpected $end"


Can changing if formats cause "Parse error: syntax error, unexpected $end"?

我对PHP相当陌生,我主要是通过在一个测试网站上编辑文件来自学的,这个测试网站是我们现场网站的副本。我们想要升级我们的WordPress网站和所有的插件,因为它已经过时将近6年了。制作网站的人在没有制作子主题的情况下放入了大量自定义代码,所以我复制了现场网站并升级了所有内容。现在,为了保持我们之前的功能,我需要做一些调整。所有这些修改都完成了,除了最后这个PHP文件。

我已经搜索了这个文件十几次了,但是我没有找到一个左括号。我尝试通过删除几个部分并使用PSPad函数来找到匹配的括号来进行测试,但我仍然得到相同的错误。我担心的一个问题是,文件有时使用if语句和:,但其他时候它使用{}。这会在服务器上造成混乱吗?

我知道这个文件相当大,但如果任何人有任何建议或帮助,他们可以提供,我将非常感激。谢谢你的宝贵时间。

编辑我已经发布了修改后的代码,其中我发现了一些if语句缺失:以及一些缺失和额外的endif语句。谢谢你们俩帮我找到这些。

<?php
/**
 * Property Default Template for Single Property View
 * Modified by RJA for APM
 * Overwrite by creating your own in the theme directory called either:
 * property.php
 * or add the property type to the end to customize further, example:
 * property-building.php or property-floorplan.php, etc.
 *
 * By default the system will look for file with property type suffix first,
 * if none found, will default to: property.php
 *
 * Copyright 2010 Andy Potanin <andy.potanin@twincitiestech.com>
 *
 * @version 1.3
 * @author Andy Potanin <andy.potnain@twincitiestech.com>
 * @package WP-Property
*/

// Uncomment to disable fancybox script being loaded on this page
//wp_deregister_script('jquery-fancybox');
//wp_deregister_script('jquery-fancybox-css');
?>
<?php get_header(); ?>
<?php the_post(); ?>

    <script type="text/javascript">
    var map;
    var marker;
    var infowindow;

    jQuery(document).ready(function() {

      if(typeof jQuery.fn.fancybox == 'function') {
        jQuery("a.fancybox_image, .gallery-item a").fancybox({
          'transitionIn'  :  'elastic',
          'transitionOut'  :  'elastic',
          'speedIn'    :  600,
          'speedOut'    :  200,
          'overlayShow'  :  false
        });
      }

      if(typeof google == 'object') {
        initialize_this_map();
      } else {
        jQuery("#property_map").hide();
      }

    });


  function initialize_this_map() {
    <?php if($coords = WPP_F::get_coordinates()) : ?>
    var myLatlng = new google.maps.LatLng(<?php echo $coords['latitude']; ?>,<?php echo $coords['longitude']; ?>);
    var myOptions = {
      zoom: <?php echo (!empty($wp_properties['configuration']['gm_zoom_level']) ? $wp_properties['configuration']['gm_zoom_level'] : 13); ?>,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }

    map = new google.maps.Map(document.getElementById("property_map"), myOptions);

    infowindow = new google.maps.InfoWindow({
      content: '<?php echo WPP_F::google_maps_infobox($post); ?>',
      maxWidth: 500
    });

     marker = new google.maps.Marker({
      position: myLatlng,
      map: map,
      title: '<?php echo addslashes($post->post_title); ?>',
      icon: '<?php echo apply_filters('wpp_supermap_marker', '', $post->ID); ?>'
    });

    google.maps.event.addListener(infowindow, 'domready', function() {
    document.getElementById('infowindow').parentNode.style.overflow='hidden';
    document.getElementById('infowindow').parentNode.parentNode.style.overflow='hidden';
   });

   setTimeout("infowindow.open(map,marker);",1000);

    <?php endif; ?>
  }

  </script>

  <div id="container" class="<?php echo (!empty($post->property_type) ? $post->property_type . "_container" : ""); ?>">
    <div id="content" role="main" class="property_content">
      <div id="post-<?php the_ID(); ?>"<?php post_class(); ?>>
      <div class="building_title_wrapper">
        <?php if ($post->property_type == 'building') : ?>
          <h1 class="property-title entry-title"><?php echo $post->building_name; 
          endif;          
          ?></h1>
        <?php
// Define Retail Address - JC
      $RetailAddress = explode(' ',$post->address);
      $RetailAddress1 = explode(',',$RetailAddress[3]);
      $RetailAddress = $post->suite." ".$RetailAddress[1]." ".$RetailAddress[2]." ".$RetailAddress1[0];    
// Define Mytype - JC                    
          $mytype = " (".ucwords($post->property_type).")";
// Define Childname - JC            
          switch($post->property_type) {
            case 'office':
            $childname = "Suite ".$post->suite.$mytype;
          break;
            case 'industrial':
            $childname = "Space ".$post->suite.$mytype;
          break;
            case 'retail':
            $childname = $RetailAddress." ".$mytype;  
          break;
      }
          ?>         
          <h1 class="property-title entry-title"><?php echo $childname; ?></h1>
      </div>

      <div class="entry-content">
          <div class="wpp_the_content"><?php @the_content(); ?></div>
        <?php if ($post->property_type<>'building') : ?>
          <div class="wpp_the_content"><a href="<?php echo $post->parent_link; ?>"><b><?php echo $post->parent_title; ?></b></a></div>
          <br>
        <?php endif; ?>
        <?php if ( empty($wp_properties['property_groups']) || $wp_properties['configuration']['property_overview']['sort_stats_by_groups'] != 'true' ) : ?>
        <?php endif; ?>
<!-- The line below paints the list of attributes -->
        <?php
       if($property['property_type']=='building')   
        //@draw_stats("make_link=true&exclude=area,property_no,available,city,building_type&sort_by_groups{$wp_properties['configuration']['address_attribute']}");
          {echo @draw_stats('display=list&class=property_stats&exclude=area,property_no,available,city,building_type&sort_by_groups=false', $property );}
        elseif ($property['property_type']=='industrial')
          {echo @draw_stats('display=list&class=property_stats&exclude=whprice,property_no,available,unit_no,city,parent_gpid&sort_by_groups=false', $property );}  
        else
          {echo @draw_stats('display=list&class=property_stats&exclude=whprice,property_no,available,unit_no,city,parent_gpid&sort_by_groups=false', $property );}
        ?>          
         </dl>          
<!-- End attribute painting -->
   <?php if ($post->property_type == 'building') : ?>
   <!-- if a flyer exists, display link here -->
          <?php
          $myproperty = $post->property_no;
          $mypath = "flyers/".$myproperty.".pdf";
          // echo "Looking for ".$mypath'n;
          if (is_file($mypath)):
          ?>
            &nbsp;&nbsp;
            <a href="http://lease.apmportland.us/<?php echo $mypath; ?>" target="_blank">View Flyer</a>
            &nbsp;(Opens in a new window and requires Adobe Reader)<br>&nbsp;<br>
          <?php endif; ?>
    <?php endif; ?>
<!-- Begin the Community Features section -->         

<!-- Begin the map section -->
        <?php if(WPP_F::get_coordinates()): ?>
          <div id="property_map" style="width:100%; height:450px"></div>
        <?php endif; ?>

        <?php if(class_exists('WPP_Inquiry')): ?>
          <h2><?php _e('Interested?','wpp') ?></h2>
          <?php WPP_Inquiry::contact_form(); ?>
        <?php endif; ?>
<!-- End map section -->    
<!-- Begin space plan section -->
        <?php
          $myunit = $post->unit_no;
          $mypath = "spaceplans/".$myunit.".jpg";
          if (is_file($mypath)): ?>
            <img src="http://lease.apmportland.us/<?php echo $mypath; ?>">
            <BR>&nbsp;<BR>
            <?php echo "Note: space plan not to scale." ?>
          <?php else: ?>
            <img src="http://lease.apmportland.us/spaceplans/blank.jpg">
          <?php endif; ?>

        <!-- End space plan section -->       
      </div><!-- .entry-content -->
    </div><!-- #post-## -->

    </div><!-- #content -->
    <a href="javascript:history.go(-1)"><b>Previous page</b></a>
  </div><!-- #container -->

<?php
  // Primary property-type sidebar.
  if ( is_active_sidebar( "wpp_sidebar_" . $post->property_type ) ) : ?>

    <div id="primary" class="widget-area <?php echo "wpp_sidebar_" . $post->property_type; ?>" role="complementary">
      <ul class="xoxo">
        <?php dynamic_sidebar( "wpp_sidebar_" . $post->property_type ); ?>
      </ul>
    </div><!-- #primary .widget-area -->

<?php endif; ?>

 <?php get_footer(); ?>

我将从这个开始,您最好使用177行中的switch/case语句,您可以查看$post->property_type:

switch($post->property_type) {
    case 'office':
    $childname = "Suite ".$post->suite.$mytype;
    break;
    case 'industrial':
    $childname = "Space ".$post->suite.$mytype;
    break;
    case 'retail':
    $childname = $RetailAddress[0]."".$mytype;
    break
}

现在是错误。似乎有一些。第一个是您缺少关闭>的地方:

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

来源:157

还有这个if块在代码中没有被关闭:

<?php if ( empty($wp_properties['property_groups']) || $wp_properties['configuration']['property_overview']['sort_stats_by_groups'] != 'true' ) : ?>

来源:199

还有这个if这里你又少了一个关闭的endif;:

<?php if ($post->property_type == 'building') : ?>

来源:239

你有这个if行没有正确打开或关闭它,你应该改变这个代码块:

<?php if(is_array($wp_properties['property_meta'])): ?>
<?php
foreach($wp_properties['property_meta'] as $meta_slug => $meta_title):
if(empty($post->$meta_slug) || $meta_slug == 'tagline'):
continue;
?>
<h2><?php echo $meta_title; ?></h2>
<p><?php echo do_shortcode(html_entity_decode($post->$meta_slug)); ?></p>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>

<一口>来源:行270 288

这就是我在快速浏览时可以选择的内容。记住,如果你要使用模板if / endif,你总是需要这样做:

if(CONDITION) :
    // do stuff
endif;

你不能忘记if语句中的:。(你已经在你的代码中完成了)

相关文章: