Giter Site home page Giter Site logo

utagawal / grav-plugin-star-ratings Goto Github PK

View Code? Open in Web Editor NEW

This project forked from getgrav/grav-plugin-star-ratings

0.0 1.0 0.0 79 KB

Grav Star Ratings Plugin

Home Page: https://getgrav.org

License: MIT License

PHP 75.53% CSS 13.05% JavaScript 11.42%

grav-plugin-star-ratings's Introduction

Star Ratings Plugin

The Star Ratings Plugin is for Grav CMS. This README.md file should be modified to describe the features, installation, configuration, and general usage of this plugin.

Description

Simple but Powerful Star Ratings plugin for all your needs. All you need is to pass it some unique id.

This allows you to easily add star ratings or a page URL, an image name, comments, pretty much anything! This plugin uses SVG-based stars so they are fully customizable in color and size, as well as stroke, and you can also configure the number of stars (default is 5). You can fully configure the behavior too, including the ability to vote in half stars or display the number of votes.

Star votes are fully cached utilizing Grav's caching mechanism, so performance is not a problem. And using stars could not be simpler!

Installation

First ensure you are running the latest Grav 1.0.10 or later. To force an upgrade of Grav run the following:

$ bin/gpm selfupgrade -f

The Star Ratings can be installed via the Admin plugin, but it can also be installed from the CLI with the following command:

$ bin/gpm install star-ratings

Configuration

The simplest way to configure the plugin is via the Admin Plugin. Simply navigate to Plugins then select Star Ratings to access the configuration options.

Alternatively, you can configure options manually by simply copying the user/plugins/star-ratings/star-ratings.yaml into user/config/plugins/star-ratings.yaml and making your modifications.

enabled: true
callback: '/star-ratings'
built_in_css: true
unique_ip_check: true
initial_stars: 0
total_stars: 5
star_size: 25
use_full_stars: false
empty_color: '#e3e3e3'
hover_color: '#1bb3e9'
active_color: '#ffd700'
use_gradient: true
star_gradient_start: '#fef7cd'
star_gradient_end: '#ffcc00'
star_shape: 'rounded' # 'rounded'
readonly: false
disable_after_rate: true
stroke_width: 0
stroke_color: '#999999'
show_count: false
global_initialization: false

Page Overrides

You can override any of these settings (except enabled) via page frontmatter overrides. For example if you have a set of defaults, and you want to override the size and stroke width of the stars on a particular page, you can do so with the following YAML in the page's frontmatter:

star-ratings:
  star_size: 45
  stroke_width: 5

These values are merged with the defaults so you don't need to include everything, only what you want to override.

Usage

To use this plugin, you simplest way to output the stars is to use the Twig function and pass it a Unique ID:

{{ stars(232) }}

This is using the hard-coded value of 232 as the unique ID. You can however, use a dynamic value such as:

{{ stars(page.route) }}

This will use the current page's route as the unique identifier.

You can also get at the raw data array:

{% set my_data = star_data(232) %}

This will return all the data for this specific item:

[
  'id' => 232,
  'count' => 2,
  'score' => 2.25
]

So you can easily display just the score with: {{ my_data.score }}.

You can also pass options to the stars function

{{ stars(page.route, { options: { readOnly: true, starSize: 50 } }) }}

Aggregate Rating

Since version 2.0.0 the plugin supports Aggregated Rating (Rich Snippets). In order to enable the functionality the first thing that needs to be done is to enable the aggregate_rating option for the page.

star-ratings:
    aggregate_rating: true

Then from your twig file you can call the stars function

stars(page.route)

Aggregation supports 2 options to customize the rich snippet output:

  1. title: defaults to the id of the element
  2. type: defaults to 'Product'

Everything else will get automatically calculated.

stars(page.route, { options: { aggregate: { type: 'Blog', title: 'My Product } } })

Assuming there's been 7 votes with the worst rating of 1 and best rating of 5 with a rating value of 2.6, this will render as:

<script type="application/ld+json">{ "@context": "http://schema.org/",
  "@type": "Blog",
  "name": "My Product",
  "aggregateRating":
    {"@type": "AggregateRating",
     "ratingValue": "2.5714285714286",
     "bestRating": "5",
     "worstRating": "1",
     "ratingCount": "7"
    }
}</script>

It is advised to use the Aggregate Rating for a single element per page, rather than trying to enable the functionality for many items.

NOTE:

If you wish to use the {{ stars(id) }} Twig call in your page's content rather than in a Twig template, you must disable page cache (see how to do this via page headers) or the stars value will be cached and will not sure an accurate representation of the state until the cache is cleared.

grav-plugin-star-ratings's People

Contributors

rhukster avatar w00fz avatar flaviocopes avatar mahagr avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.