将评论模块添加到 Smarty Template PHP 站点

发布于 2024-12-06 07:47:44 字数 1445 浏览 1 评论 0原文

我的网站是围绕 X-Cart 4.2.3 构建的,而 X-Cart 4.2.3 是围绕 Smarty 模板构建的。我正在尝试找出一种将 Facebook 评论添加到我的动态产品页面的方法 (https://developers.facebook.com/docs/reference/plugins/comments/)。每个产品页面都必须具有唯一的 URL。我找到了一个关于如何添加 LIKE 按钮的 X-cart wiki,我成功地做到了。这是 LIKE 按钮的代码:

 <iframe src="//www.facebook.com/plugins/like.php?href={$php_url.url|escape:"url"}&amp;send=false&amp;layout=standard&amp;width=350&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font=verdana&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:300px; height:80px;" allowTransparency="true"></iframe>

上面的代码与 Facebook 工具输出的代码完全相同,除了动态 URL 变量:{$php_url.url|escape:"url"} 我想基本上对 COMMENTS 模块重复相同的过程,但该模块严格来说是 xfbml,而不是 iframe,这会产生两个问题: 问题 1:即使我将 xfbml 代码逐字粘贴到我的product.tpl 模板中,我也无法让评论模块显示在商店的前端。 LIKE 按钮的 xfbml 代码也会发生同样的情况。似乎只有 iframe 可以工作。 问题 2:即使我解决了第一个问题,如何利用 fb 标记中的 URL 变量,因为它在 URL 周围有引号? 有什么想法吗? 以下是标准注释代码:

<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/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<fb:comments href="example.com" num_posts="10" width="500"></fb:comments>

My site is built around X-Cart 4.2.3, which is built around Smarty Templates. I am trying to figure out a way to add Facebook Comments to my dynamic product pages (https://developers.facebook.com/docs/reference/plugins/comments/). These have to have unique URLs for each product page. I found an X-cart wiki on how to add the LIKE button, which I did successfully. This was the code for the LIKE button:

 <iframe src="//www.facebook.com/plugins/like.php?href={$php_url.url|escape:"url"}&send=false&layout=standard&width=350&show_faces=true&action=like&colorscheme=light&font=verdana&height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:300px; height:80px;" allowTransparency="true"></iframe>

The code above is exactly the same as what Facebook's tool spits out, except for the dynamic URL variable: {$php_url.url|escape:"url"}
I wanted to basically repeat the same process for the COMMENTS module, but that one is strictly xfbml, rather than iframe, which creates two problems:
Problem 1: even if I paste the xfbml code verbatim into my product.tpl template, I can't get the comments mod to show up on the front end of the store. Same thing happens with the xfbml code of the LIKE button. Only iframe seems to work.
Problem 2: even if I solve the first problem, how to I utilize the URL variable in the fb tag, since it has quotes around the URL?
Any thoughts?
Below is the standard comments code:

<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/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<fb:comments href="example.com" num_posts="10" width="500"></fb:comments>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

耀眼的星火 2024-12-13 07:47:44

我想你想要智能文字标签。您应该在 JS 内部打开/关闭 if ,这也可能会影响您的 URL 问题。您可以在此处查看详细信息:

http://www.smarty.net/docsv2/ en/语言.function.literal

I think you want the Smart Literal tag. You should turn if on/off inside JS and may be effecting your URL issue too. You can see find details here:

http://www.smarty.net/docsv2/en/language.function.literal

眼泪淡了忧伤 2024-12-13 07:47:44

科林,
你的电话真是太棒了。你解决了问题!这段代码实际上工作得很好:

<div id="fb-root"></div>

{literal}
<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/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
{/literal}
<fb:comments href="{$php_url.url|escape:"url"}" num_posts="10" width="730"></fb:comments>

一个小问题......评论模块有时出现在文章的底部,有时则不会。我只在最新版本的 IE 中注意到这一点。就好像有时页面可以完全加载,但有时却不能。我希望这可能是我的问题。如果您有时间,请看一下这些文章:http://horrorunlimited.com/Fresh -血和烤饼/

迪玛

Colin,
brilliant call on your part. You solved the problem! This code actually works perfectly:

<div id="fb-root"></div>

{literal}
<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/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
{/literal}
<fb:comments href="{$php_url.url|escape:"url"}" num_posts="10" width="730"></fb:comments>

One small problem... the comment mod sometimes appears at the bottom of articles, and sometimes not. I've noticed this only in the latest version of IE. It's as if sometimes the pages load fully, but sometimes they don't. Could be a problem on my end, I hope. If you have a moment, take a look at these articles: http://horrorunlimited.com/Fresh-Blood-and-Crumpets/

Dima

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文