diff --git a/wp-dsfr-blocks/src/fr-latest-posts/block.json b/wp-dsfr-blocks/src/fr-latest-posts/block.json new file mode 100644 index 0000000..fb15885 --- /dev/null +++ b/wp-dsfr-blocks/src/fr-latest-posts/block.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 2, + "name": "dsfr/fr-latest-posts", + "version": "1.0.0", + "title": "Derniers articles", + "category": "widgets", + "description": "Bloc DSFR derniers articles.", + "textdomain": "wp-dsfr-blocks", + "editorScript": "file:./index.js", + "render": "file:./render.php" +} diff --git a/wp-dsfr-blocks/src/fr-latest-posts/index.js b/wp-dsfr-blocks/src/fr-latest-posts/index.js new file mode 100644 index 0000000..92fe29e --- /dev/null +++ b/wp-dsfr-blocks/src/fr-latest-posts/index.js @@ -0,0 +1,23 @@ +import { registerBlockType } from '@wordpress/blocks'; +import { __ } from '@wordpress/i18n'; +import metadata from './block.json'; + +registerBlockType( metadata.name, { + title: __( 'Dernières actualités', 'dsfr' ), + category: 'dsfr', + icon: 'megaphone', + edit: () => { + return ( +

+ { __( + 'Bloc affichant les 3 derniers articles de la catégorie actualités.', + 'dsfr' + ) } +

+ ); + }, + save: () => { + // Rendered via PHP + return null; + }, +} ); diff --git a/wp-dsfr-blocks/src/fr-latest-posts/render.php b/wp-dsfr-blocks/src/fr-latest-posts/render.php new file mode 100644 index 0000000..4de980a --- /dev/null +++ b/wp-dsfr-blocks/src/fr-latest-posts/render.php @@ -0,0 +1,27 @@ + 'actualites', + 'posts_per_page' => 4, + 'post_status' => 'publish', + ] +); + +if ( ! $posts_query->have_posts() ) { + return; +} +?> +
+
+
+ have_posts() ) : + $posts_query->the_post(); + get_template_part( 'components/loops/card-post', 0 !== $i++ ? '' : 'highlight', [ 'heading_level' => 2 ] ); + endwhile; + wp_reset_postdata(); + ?> +
+
+
diff --git a/wp-dsfr-blocks/wp-dsfr-blocks.php b/wp-dsfr-blocks/wp-dsfr-blocks.php index d85bb75..1505657 100644 --- a/wp-dsfr-blocks/wp-dsfr-blocks.php +++ b/wp-dsfr-blocks/wp-dsfr-blocks.php @@ -27,6 +27,7 @@ function dsfr_native_blocks_init() { 'fr-accordion', 'fr-accordion-title', 'fr-collapse', + 'fr-latest-posts', 'fr-quote', 'fr-tabs', 'fr-tabs-list', diff --git a/wp-dsfr-theme/inc/Services/Editor.php b/wp-dsfr-theme/inc/Services/Editor.php index c0f74b0..6c0edb4 100644 --- a/wp-dsfr-theme/inc/Services/Editor.php +++ b/wp-dsfr-theme/inc/Services/Editor.php @@ -338,6 +338,7 @@ public function gutenberg_blocks_allowed( $allowed_blocks, \WP_Block_Editor_Cont 'dsfr/fr-accordion', 'dsfr/fr-collapse', 'dsfr/fr-accordion-title', + 'dsfr/fr-latest-posts', 'dsfr/fr-quote', 'dsfr/fr-tabs', 'dsfr/fr-tabs-list',