惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
宝玉的分享
宝玉的分享
月光博客
月光博客
B
Blog
云风的 BLOG
云风的 BLOG
Google DeepMind News
Google DeepMind News
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
N
Netflix TechBlog - Medium
博客园_首页
GbyAI
GbyAI
人人都是产品经理
人人都是产品经理
A
About on SuperTechFans
Y
Y Combinator Blog
L
LangChain Blog
有赞技术团队
有赞技术团队
D
Docker
爱范儿
爱范儿
博客园 - 司徒正美
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Microsoft Security Blog
Microsoft Security Blog
D
DataBreaches.Net

Example blog

Ghost routing explained with routes.yaml examples — routes, collections & taxonomies Ghost redirects explained with practical redirects.yaml examples How to Serve JSON or XML Data in Ghost How to Change Your Default Post Template in Ghost Ghost Custom Theme Settings How to add Google Fonts to Ghost Themes How to Configure Ghost with Mailgun Ghost Theme Structure & Organization How to Make Custom Templates in Ghost Themes How to Install Ghost CMS via Ghost-CLI The best Ghost CMS hosting platforms Ghost 6.0 — Social Web and Native Ghost Analytics Ghost CMS Social web beta, email 2FA and more author social links How to keep custom design settings when updating your Ghost theme How to use the public preview card in Ghost How to add members-specific sections in Ghost How to customize the default content CTA in Ghost How to build a custom homepage in Ghost An overview of Ghost editor cards and and how they work Ghost CMS News: One-time payments & collecting sales tax How to customize the private site access template in Ghost How to add custom fonts in Ghost themes Ghost CMS News: Additional payment methods & internal linking How to use Code Injection in Ghost How to set meta data of your custom routes & collections in Ghost Ghost CMS News: TK reminders, ActivityPub and improvements How to format dates and use the date helper in Ghost Ghost CMS internationalization, custom fonts & spam protection Understanding and optimizing post and page settings in Ghost CMS Trigger the Ghost Portal popup based on page scroll progress
How to Add Disqus Comments to Ghost
Bright Themes · 2020-04-11 · via Example blog

Ghost does not have a built-in comment system yet, so in this post I will show you the steps to setup Disqus Comment System on your Ghost Theme.

Disqus is the most popular and widely used commenting platform.

Here are the steps to install Disqus for a Ghost Theme:

  1. Create a Disqus account.
  2. Create a new site.
  3. Copy the Universal Embed Code.

The code should be similar to this:

<div id="disqus_thread"></div>
<script>
  /**
   *  RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
   *  LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/
  /*
var disqus_config = function () {
this.page.url = PAGE_URL;  // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
*/
  (function () {
    // DON'T EDIT BELOW THIS LINE
    var d = document,
      s = d.createElement('script');
    s.src = 'https://disqus_shortname.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
>

Edit the post.hbs file.

Open the post.hbs file from your Ghost theme. This file should be in the following location:

/path/to/ghost/content/themes/theme_name/post.hbs

  • Paste the Universal Embed Code somewhere between the opening {{post}} and closing {{/post}} helper.
  • Replace the disqus_shortname in the Ebed Code with your actual Disqus shortname
  • Change PAGE_URL with '{{url absolute="true"}}'
  • Change PAGE_IDENTIFER with 'ghost-{{comment_id}}'
  • Save the post.hbs file.

Restart Ghost

To see the changes:

ghost restart

After the restart the Disqus comment section should appear.

It's possible to display comment count for your posts. To achieve this you need to add the following javascript snippet in your default.hbs file before the closing </body> tag:

<script
  id="dsq-count-scr"
  src="//disqus_shortname.disqus.com/count.js"
  async
></script>

Replace disqus_shortname with your Disqus shortname.

On the post page

To display the number of comments for a post add the following code:

<a href="{{url absolute='true'}}#disqus_thread">Link</a>

On the home page

If you need to display the comment count for each post on the homepage the code is similar but with an additional element, an identifier for the post.

<a
  href="{{url absolute='true'}}#disqus_thread"
  data-disqus-identifier="ghost-{{comment_id}}"
  >Post</a
>

After saving the changes you need to restart Ghost.

If you prefer Facebook comments check out our tutorial on How to Add Facebook Comments to Ghost