feat: add editorial query blocks

This commit is contained in:
chrnx committed 2026-08-11 15:27:44 -05:00
1 parent 835fb74ebf
commit 89dcc53e02
24 files changed
+1421

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "chrnx/related-posts",
"version": "0.1.0",
"title": "Related Posts",
"category": "theme",
"description": "Related stories selected by topic, tags, and recency.",
"textdomain": "chrnx",
"usesContext": ["postId", "postType"],
"attributes": {
"limit": { "type": "integer", "default": 3, "minimum": 1, "maximum": 12 },
"headingLevel": { "type": "integer", "default": 2, "enum": [2, 3, 4, 5, 6] }
},
"supports": { "html": false, "align": ["wide", "full"] },
"render": "file:./render.php"
}
+25
View File
@@ -0,0 +1,25 @@
<?php
/**
* Related Posts block render.
*
* @package CHRNX
*/
$chrnx_post_id = isset( $block->context['postId'] ) ? absint( $block->context['postId'] ) : get_the_ID();
$chrnx_limit = isset( $attributes['limit'] ) ? min( 12, max( 1, absint( $attributes['limit'] ) ) ) : 3;
$chrnx_ids = chrnx_get_related_post_ids( $chrnx_post_id, $chrnx_limit );
if ( empty( $chrnx_ids ) ) {
return;
}
$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 );
?>
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-related-posts' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> aria-labelledby="chrnx-related-posts-title-<?php echo esc_attr( $chrnx_post_id ); ?>">
<h<?php echo esc_attr( $chrnx_heading ); ?> id="chrnx-related-posts-title-<?php echo esc_attr( $chrnx_post_id ); ?>"><?php echo esc_html__( 'Related stories', 'chrnx' ); ?></h<?php echo esc_attr( $chrnx_heading ); ?>>
<div class="chrnx-related-posts__grid">
<?php
foreach ( $chrnx_ids as $chrnx_related_id ) {
echo chrnx_get_editorial_card_markup( $chrnx_related_id, min( 6, $chrnx_heading + 1 ), 'chrnx-related-card' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
?>
</div>
</section>