Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions wp-dsfr-blocks/src/fr-latest-posts/block.json
Original file line number Diff line number Diff line change
@@ -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"
}
23 changes: 23 additions & 0 deletions wp-dsfr-blocks/src/fr-latest-posts/index.js
Original file line number Diff line number Diff line change
@@ -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 (
<p>
{ __(
'Bloc affichant les 3 derniers articles de la catégorie actualités.',
'dsfr'
) }
</p>
);
},
save: () => {
// Rendered via PHP
return null;
},
} );
27 changes: 27 additions & 0 deletions wp-dsfr-blocks/src/fr-latest-posts/render.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
$posts_query = new WP_Query(
[
'category_name' => 'actualites',
'posts_per_page' => 4,
'post_status' => 'publish',
]
);

if ( ! $posts_query->have_posts() ) {
return;
}
?>
<section class="latest-posts" style="max-width: 78rem;">
<div class="fr-container">
<div class="grid grid--fr-card-post" data-grid-size="3">
<?php
$i = 0;
while ( $posts_query->have_posts() ) :
$posts_query->the_post();
get_template_part( 'components/loops/card-post', 0 !== $i++ ? '' : 'highlight', [ 'heading_level' => 2 ] );
endwhile;
wp_reset_postdata();
?>
</div>
</div>
</section>
1 change: 1 addition & 0 deletions wp-dsfr-blocks/wp-dsfr-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions wp-dsfr-theme/inc/Services/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down