FEATURE Introducing the block

This commit is contained in:
Antoine M 2026-03-25 15:59:11 +01:00
parent 90a7a16dfb
commit 837c445bbc
7 changed files with 87 additions and 0 deletions

View File

@ -0,0 +1,19 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "carhop-blocks/dbmob-archives",
"version": "0.1.0",
"title": "Archives des notices biographiques",
"category": "carhop-blocks",
"icon": "smiley",
"description": "Archives des notices biographiques",
"supports": {
"html": false
},
"textdomain": "carhop-blocks",
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"style": "file:./style-index.css",
"render": "file:./render.php",
"viewScript": "file:./view.js"
}

View File

@ -0,0 +1,11 @@
import { __ } from "@wordpress/i18n";
import { useBlockProps } from "@wordpress/block-editor";
import "./editor.scss";
import { ServerSideRender } from "@wordpress/server-side-render";
export default function Edit() {
return (
<div {...useBlockProps()}>
<ServerSideRender block="carhop-blocks/dbmob-archives" />
</div>
);
}

View File

@ -0,0 +1,7 @@
import { registerBlockType } from "@wordpress/blocks";
import "./style.scss";
import Edit from "./edit";
import metadata from "./block.json";
registerBlockType(metadata.name, {
edit: Edit,
});

View File

@ -0,0 +1,50 @@
<?php
$args = array(
'post_type' => 'dbmob',
'posts_per_page' => -1,
);
$query = new WP_Query($args);
$post_count = $query->found_posts;
?>
<section <?php echo get_block_wrapper_attributes(); ?>>
<h2>Les notices rédigées par le CARHOP</h2>
<div class="notice-toolbar">
<h2 class="post-count">
<span class="post-count__count">
<?php echo $post_count; ?>
</span>
<span class="post-count__text">
<?php _e('notices biographiques', 'carhop-blocks'); ?>
</span>
</h2>
<div class="search-bar">
<label for="search-input"><?php _e('Rechercher une notice par nom', 'carhop-blocks'); ?></label>
<input type="text" placeholder="<?php _e('Rechercher par nom', 'carhop-blocks'); ?>">
</div>
</div>
<?php if ($query->have_posts()) : ?>
<div class="dbmob-grid">
<?php while ($query->have_posts()) : $query->the_post(); ?>
<?php $maitron_url = get_field('maitron_url', get_the_ID()); ?>
<?php get_template_part('template-parts/components/cards/post-card', null, array(
'ID' => get_the_ID(),
'current_post_type' => 'dbmob',
'has_external_link' => isset($maitron_url) && !empty($maitron_url),
'external_link' => $maitron_url,
'external_link_text' => 'Voir la notice',
)); ?>
<?php endwhile; ?>
</ul>
<?php endif; ?>
</section>