Can changing if formats cause "Parse error: syntax error, 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)):
?>
<a href="http://lease.apmportland.us/<?php echo $mypath; ?>" target="_blank">View Flyer</a>
(Opens in a new window and requires Adobe Reader)<br> <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> <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
语句中的:
。 (您在代码中所做的)
我是 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)):
?>
<a href="http://lease.apmportland.us/<?php echo $mypath; ?>" target="_blank">View Flyer</a>
(Opens in a new window and requires Adobe Reader)<br> <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> <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
语句中的:
。 (您在代码中所做的)