Skip to content

Advent calendar in WordPress

A 24-door Advent calendar where each surprise only opens from its day in December, with opened doors remembered.

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

calendrier-avent.php
<?php
/**
 * Plugin Name: Forge, Calendrier de l’Avent
 * Description: Un calendrier de l’Avent de 24 cases où chaque surprise ne s’ouvre qu’à partir de son jour de décembre, les cases ouvertes étant mémorisées. Ajoute la composition « Calendrier de l’Avent » à 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-calendrier-avent
 *
pattern.html
<!-- wp:html -->
<section class="cav" data-cav data-cav-preview aria-labelledby="cav-titre">
        <p class="cav-eyebrow">Librairie Les Mots Passants · Nantes</p>
        <h2 class="cav-title" id="cav-titre">Notre calendrier de l’Avent</h2>
        <p class="cav-text">Chaque jour de décembre, une case s’ouvre : une remise, un coup de cœur ou un rendez-vous en boutique.</p>
        <p class="cav-hint" data-cav-hint>Aperçu : en décembre, une case ne s’ouvre qu’à partir de son jour. Hors saison, toutes les cases sont ouvertes pour découvrir le calendrier (retirez l’attribut data-cav-preview pour l’interdire).</p>
        <ol class="cav-grid">
          <li class="cav-cell"><button class="cav-door" type="button" data-cav-door="1" data-cav-text="Un marque-page brodé offert pour tout achat aujourd’hui.">1<span class="cav-sr" data-cav-state> (fermée)</span></button></li>
          <li class="cav-cell"><button class="cav-door" type="button" data-cav-door="2" data-cav-text="Coup de cœur : « Le Pays des autres » de Leïla Slimani, à emballer.">2<span class="cav-sr" data-cav-state> (fermée)</span></button></li>
          <li class="cav-cell"><button class="cav-door" type="button" data-cav-door="3" data-cav-text="Livraison offerte dès 25 € jusqu’à dimanche.">3<span class="cav-sr" data-cav-state> (fermée)</span></button></li>
          <li class="cav-cell"><button class="cav-door" type="button" data-cav-door="4" data-cav-text="Lecture de contes pour les 4-8 ans samedi à 10 h 30.">4<span class="cav-sr" data-cav-state> (fermée)</span></button></li>
          <li class="cav-cell"><button class="cav-door" type="button" data-cav-door="5" data-cav-text="−10 % sur toutes les bandes dessinées ce week-end.">5<span class="cav-sr" data-cav-state> (fermée)</span></button></li>
script.js
(() => {
  if (!document.querySelector(".cav")) return;
  document.querySelectorAll("[data-cav]").forEach((root) => {
    const on = (el, type, fn) => el.addEventListener(type, fn);
    const key = "forge-calendrier-avent";
    const now = new Date();
    const december = now.getMonth() === 11;
    const preview = root.hasAttribute("data-cav-preview") && !december;
    const panel = root.querySelector("[data-cav-panel]");
    let opened = [];
    try {
      opened = JSON.parse(localStorage.getItem(key) || "[]");
style.css
:root {
  --cav-card: #ffffff;
  --cav-text: #18291f;
  --cav-muted: #46584c;
  --cav-soft: #eef4ef;
  --cav-door: #1f4d36;
  --cav-door-text: #fdf3d4;
  --cav-open: #f7e7b4;
  --cav-open-text: #4a3a0c;
  --cav-accent: #a16207;
  --demo-calendrier-avent-bg: #e8efe9;
  --demo-calendrier-avent-text: #18291f;

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

Cards components in WordPress
  • A single-plan pricing card: struck-through price and discount, a places-left gauge driven by a data attribute, the list of everything included and a booking button that turns into a waiting list once sold out.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Three treatment cards in accessible neumorphism: gently raised surfaces, buttons that sink in when activated, a light/dark switch for the block itself. 3:1 outlines and AA text kept.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Four fully clickable workshop cards in a neo-brutalist style: thick border, solid offset shadow and a card that sinks onto its shadow on hover or focus. Pastel tones, dark mode, no JavaScript.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Three brutalist service cards: one-pixel border, hard offset shadow that lifts on hover and sinks on click, large type, accent and dark variants. No JavaScript.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A mobile page to link from your social profiles: portrait, name, priority links (booking, WhatsApp, website, reviews, call), opening hours with an open or closed status, social links and a share button, in dependency-free HTML and CSS.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A seasonal promotion card with a struck-through price and discount that announces by itself whether the offer is coming, how many days are left or that it is over.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component