feat: add editorial query blocks
This commit is contained in:
24 files changed
+1421
No files matched your search
@@ -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"
|
||||
}
|
||||
@@ -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(); ?>
|
||||
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user