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/featured-stories",
"version": "0.1.0",
"title": "Featured Stories",
"category": "theme",
"description": "A sticky-led selection of topic-diverse stories.",
"textdomain": "chrnx",
"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"] },
"style": "file:./style.css",
"render": "file:./render.php"
}
+23
View File
@@ -0,0 +1,23 @@
<?php
/**
* Featured Stories block render.
*
* @package CHRNX
*/
$chrnx_limit = isset( $attributes['limit'] ) ? min( 12, max( 1, absint( $attributes['limit'] ) ) ) : 3;
$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 );
$chrnx_ids = chrnx_get_featured_story_ids( $chrnx_limit );
if ( empty( $chrnx_ids ) ) {
return;
}
?>
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-featured-stories' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> aria-label="<?php echo esc_attr__( 'Featured stories', 'chrnx' ); ?>">
<div class="chrnx-featured-stories__grid">
<?php
foreach ( $chrnx_ids as $chrnx_post_id ) {
echo chrnx_get_editorial_card_markup( $chrnx_post_id, $chrnx_heading, 'chrnx-featured-story' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
?>
</div>
</section>
+27
View File
@@ -0,0 +1,27 @@
.chrnx-featured-stories__grid {
display: grid;
gap: var(--wp--preset--spacing--40, 1.5rem);
grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
}
.chrnx-featured-story,
.chrnx-featured-story__link {
height: 100%;
}
.chrnx-featured-story__link {
display: flex;
flex-direction: column;
}
.chrnx-featured-story__image,
.chrnx-featured-story__fallback {
aspect-ratio: 3 / 2;
display: block;
object-fit: cover;
width: 100%;
}
.chrnx-featured-story__fallback {
background: linear-gradient(135deg, var(--wp--preset--color--violet), var(--wp--preset--color--green));
}
+16
View File
@@ -0,0 +1,16 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "chrnx/journal-stream",
"version": "0.1.0",
"title": "Journal Stream",
"category": "theme",
"description": "The filterable chronological journal.",
"textdomain": "chrnx",
"attributes": {
"headingLevel": { "type": "integer", "default": 2, "enum": [2, 3, 4, 5, 6] }
},
"supports": { "html": false, "align": ["wide", "full"] },
"style": "file:./style.css",
"render": "file:./render.php"
}
+94
View File
@@ -0,0 +1,94 @@
<?php
/**
* Journal Stream block render.
*
* @package CHRNX
*/
// Read-only filters do not change server state; every value is validated by the query service.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$chrnx_request = is_array( $_GET ) ? $_GET : array();
$chrnx_args = chrnx_get_journal_query_args( $chrnx_request );
$chrnx_query = new WP_Query( $chrnx_args );
$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 );
$chrnx_topic = chrnx_validate_editorial_term_slug( $chrnx_request['chrnx_topic'] ?? '', 'chrnx_topic' );
$chrnx_language = chrnx_validate_editorial_term_slug( $chrnx_request['chrnx_language'] ?? '', 'chrnx_language' );
$chrnx_search = $chrnx_args['s'] ?? '';
?>
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-journal-stream' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> aria-labelledby="chrnx-journal-title">
<h<?php echo esc_attr( $chrnx_heading ); ?> id="chrnx-journal-title"><?php echo esc_html__( 'Journal', 'chrnx' ); ?></h<?php echo esc_attr( $chrnx_heading ); ?>>
<form class="chrnx-journal-stream__filters" method="get" action="<?php echo esc_url( remove_query_arg( array( 'chrnx_topic', 'chrnx_language', 's', 'paged' ) ) ); ?>">
<label>
<span><?php echo esc_html__( 'Topic', 'chrnx' ); ?></span>
<select name="chrnx_topic">
<option value=""><?php echo esc_html__( 'All topics', 'chrnx' ); ?></option>
<?php
foreach ( get_terms(
array(
'taxonomy' => 'chrnx_topic',
'hide_empty' => false,
)
) as $chrnx_term ) :
?>
<option value="<?php echo esc_attr( $chrnx_term->slug ); ?>" <?php selected( $chrnx_topic, $chrnx_term->slug ); ?>><?php echo esc_html( $chrnx_term->name ); ?></option>
<?php endforeach; ?>
</select>
</label>
<label>
<span><?php echo esc_html__( 'Language', 'chrnx' ); ?></span>
<select name="chrnx_language">
<option value=""><?php echo esc_html__( 'All languages', 'chrnx' ); ?></option>
<?php
foreach ( get_terms(
array(
'taxonomy' => 'chrnx_language',
'hide_empty' => false,
)
) as $chrnx_term ) :
?>
<option value="<?php echo esc_attr( $chrnx_term->slug ); ?>" <?php selected( $chrnx_language, $chrnx_term->slug ); ?>><?php echo esc_html( $chrnx_term->name ); ?></option>
<?php endforeach; ?>
</select>
</label>
<label>
<span><?php echo esc_html__( 'Search', 'chrnx' ); ?></span>
<input type="search" name="s" value="<?php echo esc_attr( $chrnx_search ); ?>">
</label>
<button type="submit"><?php echo esc_html__( 'Filter', 'chrnx' ); ?></button>
</form>
<?php if ( $chrnx_query->have_posts() ) : ?>
<ol class="chrnx-journal-stream__list">
<?php foreach ( $chrnx_query->posts as $chrnx_post ) : ?>
<?php if ( chrnx_is_eligible_editorial_post( $chrnx_post ) ) : ?>
<li><?php echo chrnx_get_editorial_card_markup( $chrnx_post->ID, min( 6, $chrnx_heading + 1 ), 'chrnx-journal-card' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ol>
<?php if ( $chrnx_query->max_num_pages > 1 ) : ?>
<?php
$chrnx_filter_args = array_filter(
array(
'chrnx_topic' => $chrnx_topic,
'chrnx_language' => $chrnx_language,
's' => $chrnx_search,
),
'strlen'
);
$chrnx_links = paginate_links(
array(
'total' => $chrnx_query->max_num_pages,
'current' => $chrnx_args['paged'],
'add_args' => $chrnx_filter_args,
'type' => 'list',
)
);
?>
<?php if ( is_string( $chrnx_links ) ) : ?>
<nav class="chrnx-journal-stream__pagination" aria-label="<?php echo esc_attr__( 'Journal pages', 'chrnx' ); ?>"><?php echo wp_kses_post( $chrnx_links ); ?></nav>
<?php endif; ?>
<?php endif; ?>
<?php else : ?>
<p class="chrnx-journal-stream__empty"><?php echo esc_html__( 'No journal entries match these filters yet.', 'chrnx' ); ?></p>
<?php endif; ?>
</section>
<?php wp_reset_postdata(); ?>
+31
View File
@@ -0,0 +1,31 @@
.chrnx-journal-stream__filters {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
.chrnx-journal-stream__filters label {
display: grid;
gap: 0.25rem;
}
.chrnx-journal-stream__list {
display: grid;
gap: 2rem;
list-style: none;
padding: 0;
}
.chrnx-journal-card__fallback {
background: var(--wp--preset--color--panel);
display: block;
min-height: 8rem;
}
.chrnx-journal-stream__pagination .page-numbers {
display: flex;
flex-wrap: wrap;
gap: 0.75rem;
list-style: none;
padding: 0;
}
+16
View File
@@ -0,0 +1,16 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "chrnx/latest-podcast",
"version": "0.1.0",
"title": "Latest Podcast",
"category": "theme",
"description": "A linked card for the latest podcast episode.",
"textdomain": "chrnx",
"attributes": {
"headingLevel": { "type": "integer", "default": 2, "enum": [2, 3, 4, 5, 6] }
},
"supports": { "html": false, "align": ["wide", "full"] },
"style": "file:./style.css",
"render": "file:./render.php"
}
+16
View File
@@ -0,0 +1,16 @@
<?php
/**
* Latest Podcast block render.
*
* @package CHRNX
*/
$chrnx_post_id = chrnx_get_latest_podcast_id();
if ( 0 === $chrnx_post_id ) {
return;
}
$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 );
?>
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-latest-podcast' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> aria-label="<?php echo esc_attr__( 'Latest podcast', 'chrnx' ); ?>">
<?php echo chrnx_get_editorial_card_markup( $chrnx_post_id, $chrnx_heading, 'chrnx-podcast-card' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</section>
+16
View File
@@ -0,0 +1,16 @@
.chrnx-latest-podcast {
border: 1px solid var(--wp--preset--color--border, currentcolor);
padding: var(--wp--preset--spacing--40, 1.5rem);
}
.chrnx-podcast-card__image,
.chrnx-podcast-card__fallback {
aspect-ratio: 3 / 2;
display: block;
object-fit: cover;
width: 100%;
}
.chrnx-podcast-card__fallback {
background: linear-gradient(135deg, var(--wp--preset--color--green), var(--wp--preset--color--violet));
}
+13
View File
@@ -0,0 +1,13 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "chrnx/podcast-meta",
"version": "0.1.0",
"title": "Podcast Metadata",
"category": "theme",
"description": "Safe episode details for the current post.",
"textdomain": "chrnx",
"usesContext": ["postId", "postType"],
"supports": { "html": false },
"render": "file:./render.php"
}
+30
View File
@@ -0,0 +1,30 @@
<?php
/**
* Podcast Metadata block render.
*
* @package CHRNX
*/
$chrnx_post_id = isset( $block->context['postId'] ) ? absint( $block->context['postId'] ) : get_the_ID();
$chrnx_episode = chrnx_sanitize_episode_number( get_post_meta( $chrnx_post_id, 'chrnx_episode_number', true ) );
$chrnx_duration = chrnx_sanitize_episode_duration( get_post_meta( $chrnx_post_id, 'chrnx_episode_duration', true ) );
$chrnx_participants = chrnx_sanitize_episode_participants( get_post_meta( $chrnx_post_id, 'chrnx_episode_participants', true ) );
$chrnx_url = chrnx_sanitize_canonical_episode_url( get_post_meta( $chrnx_post_id, 'canonical_episode_url', true ) );
if ( 0 === $chrnx_episode && '' === $chrnx_duration && empty( $chrnx_participants ) && '' === $chrnx_url ) {
return;
}
?>
<dl <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-podcast-meta' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<?php if ( $chrnx_episode > 0 ) : ?>
<div class="chrnx-podcast-meta__item"><dt><?php echo esc_html__( 'Episode', 'chrnx' ); ?></dt><dd><?php echo esc_html( number_format_i18n( $chrnx_episode ) ); ?></dd></div>
<?php endif; ?>
<?php if ( '' !== $chrnx_duration ) : ?>
<div class="chrnx-podcast-meta__item"><dt><?php echo esc_html__( 'Duration', 'chrnx' ); ?></dt><dd><?php echo esc_html( $chrnx_duration ); ?></dd></div>
<?php endif; ?>
<?php if ( ! empty( $chrnx_participants ) ) : ?>
<div class="chrnx-podcast-meta__item"><dt><?php echo esc_html__( 'Participants', 'chrnx' ); ?></dt><dd><?php echo esc_html( implode( ', ', $chrnx_participants ) ); ?></dd></div>
<?php endif; ?>
<?php if ( '' !== $chrnx_url ) : ?>
<div class="chrnx-podcast-meta__item"><dt><?php echo esc_html__( 'Episode page', 'chrnx' ); ?></dt><dd><a href="<?php echo esc_url( $chrnx_url ); ?>"><?php echo esc_html__( 'Open canonical episode page', 'chrnx' ); ?></a></dd></div>
<?php endif; ?>
</dl>
+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>
+15
View File
@@ -0,0 +1,15 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "chrnx/subscribe-cta",
"version": "0.1.0",
"title": "Subscribe CTA",
"category": "theme",
"description": "A call to action linked to the configured subscribe page.",
"textdomain": "chrnx",
"attributes": {
"headingLevel": { "type": "integer", "default": 2, "enum": [2, 3, 4, 5, 6] }
},
"supports": { "html": false, "align": ["wide", "full"] },
"render": "file:./render.php"
}
+18
View File
@@ -0,0 +1,18 @@
<?php
/**
* Subscribe CTA block render.
*
* @package CHRNX
*/
$chrnx_url = chrnx_get_subscribe_url();
if ( '' === $chrnx_url ) {
return;
}
$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 );
?>
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-subscribe-cta' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<h<?php echo esc_attr( $chrnx_heading ); ?> class="chrnx-subscribe-cta__title"><?php echo esc_html__( 'Stay in the loop', 'chrnx' ); ?></h<?php echo esc_attr( $chrnx_heading ); ?>>
<p><?php echo esc_html__( 'Get new stories and episodes when they are published.', 'chrnx' ); ?></p>
<a class="chrnx-subscribe-cta__link" href="<?php echo esc_url( $chrnx_url ); ?>"><?php echo esc_html__( 'Subscribe', 'chrnx' ); ?></a>
</section>
+16
View File
@@ -0,0 +1,16 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "chrnx/topic-hero",
"version": "0.1.0",
"title": "Topic Hero",
"category": "theme",
"description": "A fixed-art hero for an editorial topic.",
"textdomain": "chrnx",
"attributes": {
"topic": { "type": "string", "enum": ["research", "code", "literature", "music", "podcasts", "life", "gaming"] },
"headingLevel": { "type": "integer", "default": 2, "enum": [2, 3, 4, 5, 6] }
},
"supports": { "html": false, "align": ["wide", "full"] },
"render": "file:./render.php"
}
+32
View File
@@ -0,0 +1,32 @@
<?php
/**
* Topic Hero block render.
*
* @package CHRNX
*/
$chrnx_topic = isset( $attributes['topic'] ) && is_string( $attributes['topic'] ) ? $attributes['topic'] : '';
if ( '' === $chrnx_topic && is_tax( 'chrnx_topic' ) ) {
$chrnx_queried = get_queried_object();
$chrnx_topic = $chrnx_queried instanceof WP_Term ? $chrnx_queried->slug : '';
}
$chrnx_asset = chrnx_get_topic_art_asset( $chrnx_topic );
if ( '' === $chrnx_asset ) {
return;
}
$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 );
$chrnx_term = get_term_by( 'slug', $chrnx_topic, 'chrnx_topic' );
$chrnx_label = $chrnx_term instanceof WP_Term ? $chrnx_term->name : ucfirst( $chrnx_topic );
?>
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-topic-hero is-topic-' . sanitize_html_class( $chrnx_topic ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<div class="chrnx-topic-hero__content">
<h<?php echo esc_attr( $chrnx_heading ); ?> class="chrnx-topic-hero__title"><?php echo esc_html( $chrnx_label ); ?></h<?php echo esc_attr( $chrnx_heading ); ?>>
</div>
<div class="chrnx-topic-hero__art">
<?php if ( is_readable( get_theme_file_path( $chrnx_asset ) ) ) : ?>
<img src="<?php echo esc_url( get_theme_file_uri( $chrnx_asset ) ); ?>" alt="<?php echo esc_attr( $chrnx_label ); ?>">
<?php else : ?>
<span class="chrnx-topic-hero__fallback" aria-hidden="true"></span>
<?php endif; ?>
</div>
</section>