Skip to content

Reviews filtered by rating in WordPress

A customer reviews section with average rating and star distribution; each bar is a button that filters the reviews with that rating.

Here is an excerpt of this component's code in WordPress. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in WordPress

pattern.html
<!-- wp:html -->
<section class="tfn" data-tfn aria-labelledby="tfn-titre">
        <div class="tfn-summary">
          <h2 class="tfn-title" id="tfn-titre">Avis clients</h2>
          <p class="tfn-avg"><strong class="tfn-avgnum">4,4</strong> sur 5 · 7 avis vérifiés</p>
          <ul class="tfn-bars" aria-label="Filtrer par note" data-tfn-bars hidden>
            <li><button class="tfn-bar" type="button" aria-pressed="false" data-tfn-filter="5">
              <span class="tfn-blabel">5 étoiles</span>
              <span class="tfn-track" aria-hidden="true"><span class="tfn-fill" style="transform: scaleX(0.571)"></span></span>
              <span class="tfn-bcount">4 avis</span>
            </button></li>
            <li><button class="tfn-bar" type="button" aria-pressed="false" data-tfn-filter="4">
script.js
(() => {
  if (!document.querySelector(".tfn")) return;
  document.querySelectorAll("[data-tfn]").forEach((root) => {
    const on = (el, type, fn) => el.addEventListener(type, fn);
    const buttons = [...root.querySelectorAll("[data-tfn-filter]")];
    const cards = [...root.querySelectorAll("[data-tfn-note]")];
    const count = root.querySelector("[data-tfn-count]");
    root.querySelector("[data-tfn-bars]").hidden = false;

    buttons.forEach((button) => {
      on(button, "click", () => {
        // A second press on the active note brings every review back.
style.css
:root {
  --tfn-bg: #f6f4ef;
  --tfn-card: #ffffff;
  --tfn-text: #22201b;
  --tfn-muted: #57524a;
  --tfn-line: #e4dfd5;
  --tfn-track: #ebe6dc;
  --tfn-star: #a16207;
  --tfn-accent: #1e3a8a;
  --tfn-pressed: #e8edfb;
  --demo-temoignages-filtre-note-bg: #ece8df;
  --demo-temoignages-filtre-note-text: #22201b;
temoignages-filtre-note.php
<?php
/**
 * Plugin Name: Forge, Avis filtrables par note
 * Description: Une section d’avis clients avec note moyenne et répartition des étoiles ; chaque barre est un bouton qui filtre les avis de cette note. Ajoute la composition « Avis filtrables par note » à l'éditeur de blocs.
 * Version: 1.0.0
 * Requires at least: 6.6
 * Requires PHP: 8.1
 * Author: Forge
 * License: GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: forge-temoignages-filtre-note
 *

Free component: copy it freely, including for commercial projects.

Testimonials components in WordPress
  • A reviews section for local shops: average star rating out of 5, a star breakdown that animates into view and the three latest reviews signed with a first name and a town.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A CSS-drawn video poster with a play button, the testimonial's key quote, its author, and the timestamped transcript in a collapsible panel.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Three customer reviews as cards, with star rating and customer tenure.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A row of client references as wordmarks, followed by a representative quote.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A single highlighted quote, with the name and role of its author.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component