【问题标题】:Set up Disqus Multiple Canonical URL in Magento在 Magento 中设置 Disqus 多个规范 URL
【发布时间】:2017-07-11 06:28:51
【问题描述】:

我正在尝试将 Disqus 集成到我的测试 Magento 网站上。我正在使用 NeoTheme 博客扩展,但是我禁用了内置评论部分并将其更改为 disqus。

问题在于规范网址。我有一个主类别http://?????.com/news-and-media/,它有一个子类别 /blog 和 /news 等。博客页面可以通过http://????/.com/news-and-media/blog-contenthttp://????/.com/news-and-media/blog/blog-content 访问,都显示相同的内容。我尝试对每个 url 发表评论,但是其他页面中缺少评论,反之亦然。

这是我目前的进步。

我的 phtml

<div id="disqus_thread"></div>
<script>
var disqus_config = function () {
this.page.url = 'http://?????.com/news-and-media/';
this.page.identifier = 'blog';
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://????-com.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>

我的 local.xml

<neotheme_blog_post_index>
    <reference name="disquscomment">
        <block type="core/template" name="dcomment" template="disqus-comments.phtml" />
    </reference>        
</neotheme_blog_post_index>

您对此规范有解决方案吗?我似乎无法理解文档和示例。

https://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables

How to make Disqus to work with url routing?

【问题讨论】:

  • 您是否在后端设置了规范?
  • 是的,我手动将其添加到设计布局 xml 中。

标签: javascript php magento disqus


【解决方案1】:

您必须使用 javascript 获取 rel 规范值并将其用作您的页面标识符。我不确定这是否有效。

var canonical = "";
var links = document.getElementsByTagName("link");
for (var i = 0; i < links.length; i ++) {
if (links[i].getAttribute("rel") === "canonical") {
    canonical = links[i].getAttribute("href")
}
}
var disqus_config = function () {
this.page.url = '';
this.page.identifier = canonical;
};
(function() { // DON'T EDIT BELOW THIS LINE

查看此链接以供参考。 http://javascript.qahowto.com/Obtaining-canonical-url-using-JavaScript-javascript-url-5b420a

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    • 2013-08-14
    • 1970-01-01
    相关资源
    最近更新 更多