【问题标题】:Parse error: syntax error, unexpected '<' in footer.php解析错误:语法错误,footer.php 中出现意外的“<”
【发布时间】:2015-03-15 10:02:01
【问题描述】:

我收到此错误:

解析错误:语法错误,/home/.../public_html/lagatar.com/wp-content/themes/.../footer.php 中出现意外的 '

在我的footer.php 中添加了facebook 的likebox 代码后,我的网站页脚下方出现了上述错误。

<?php

/* Prevent direct access to this file */
if ( !defined('WP_CONTENT_DIR') )
    die('Please do not access this file directly.');

<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=204491109624023&version=v2.0";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

/* WordPress and a lot of plugins require the function in this file, so I guess we have to use it :-(. */
wp_footer();


Display::body_close();

Display::html_close();

【问题讨论】:

  • 不需要反引号来格式化代码块 - 只需使用代码按钮。

标签: php wordpress facebook-javascript-sdk facebook-like facebook-php-sdk


【解决方案1】:

您不小心在 PHP 标记中插入了 HTML,您应该这样做:

<?php    
/* Prevent direct access to this file */ if ( !defined('WP_CONTENT_DIR') )  die('Please do not access this file directly.');    
?>

<div id="fb-root"></div> <script>(function(d, s, id) {  var js, fjs = d.getElementsByTagName(s)[0];  if (d.getElementById(id)) return;  js = d.createElement(s); js.id = id;  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=204491109624023&version=v2.0"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script>

<?php    
/* WordPress and a lot of plugins require the function in this file, so I guess we have to use it :-(. */ 
wp_footer();

Display::body_close();

Display::html_close();

【讨论】:

  • 您的代码删除了错误。但是类似 fb 的框没有正确显示(只有一小部分可见)。 [请看我网站的右下角]。仅供参考:fb cmets 也有相同的外观问题。以前两个likebox n cmets 都很好,但存在解析错误。 @Grzegorz Pawlik
  • 你现在的问题是FB框的大小。它的渲染很好,但是有一些 CSS 规则会覆盖它的大小。您可以使用以下代码修复它: .widget_text .fb_iframe_widget iframe { width:300px !important;高度:240 像素!重要 }
  • 我补充说。现在 fb likebox 正在玩捉迷藏。它仅在我向下滚动时出现。那么fb评论呢?只有一小部分是可见的。我不知道是什么造成了所有这些问题……仅供参考;我所做的所有网站更改都是缩小其他一些东西以提高页面速度。还请查看我最近的帖子/观看次数最多的...图像缩略图应该在那里,但它不在那里。简而言之:据我所知,fb likebox、fb cmets 和最近发布/观看次数最多的插件在我做错事后同时开始出现问题(不知道我做了什么!)@Grzegorz Pawlik
猜你喜欢
  • 2014-08-08
  • 1970-01-01
  • 2013-01-11
  • 1970-01-01
  • 1970-01-01
  • 2015-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多