欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

How to add rating star to Blog

程序员文章站 2022-04-17 17:47:18
...

See orginal article https://dyingdown.github.io/2020/08/11/How-to-add-rating-star-to-Blog/

Widget Pack

We use Widget Pack to get the function. It’s an powerful widget that has many function. Here we will just use it’s rating function because I thinks valine is more beautiful…

Preview

Here is a preview of the function. The color of the stars can be customized.

How to add rating star to Blog

Preparation

First Sign Up for an account.
How to add rating star to Blog
Follow it’s steps. It will let you fill your website address.

After some steps, you will get your ID here:
How to add rating star to Blog
Click here, you can set how can reader vote for your article.
How to add rating star to Blog
Select the drop down box to turn on anonymous rating.
How to add rating star to Blog
And there you can change color of stars and number of stars.
How to add rating star to Blog
Then click SAVE SETTING.

Add Function

Create a new file called startRating.html or .pug

<center>
<div id="wpac-rating"></div>
</center>
script(type="text/javascript").
    wpac_init = window.wpac_init || [];
    wpac_init.push({widget: 'Rating', id: #{theme.star.id}, color: "#{theme.star.color}"});
    (function() {
        if ('WIDGETPACK_LOADED' in window) return;
        WIDGETPACK_LOADED = true;
        var mc = document.createElement('script');
        mc.type = 'text/javascript';
        mc.async = true;
        mc.src = 'https://embed.widgetpack.com/widget.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(mc, s.nextSibling);
    })();

But, if you are using it on your website, you can just copy the code he gives you.

Then find the file post.pug. Find the bottom of the article and include the file starRating.pug.

if theme.star.on
    include ... .pug

After that, find your theme _config.yml and type these:

# Rating star function 打星功能
star:
  on: true
  id: 26703 # app id 用户id
  color: fadb14 # color of stars in Hexadecimal 星星的颜色

Save and preview.

相关标签: Blog