Projects were hardcoded h3 elements in a pattern: no URL, no feed, no search, uneditable without touching PHP. They follow the podcast model now, a chrnx_topic term plus posts. Adds a chrnx_project_featured flag with an editor toggle so the stage lists chosen projects first and fills with the most recent. Sticky was already spoken for by the home featured stories, so the choice needed its own signal. journal-stream gains a pinned topic attribute, reusing the archive filter, pagination and empty state it already had. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
134 lines
6.8 KiB
PHP
134 lines
6.8 KiB
PHP
<?php
|
|
/**
|
|
* Journal Stream block render.
|
|
*
|
|
* @package CHRNX
|
|
*/
|
|
|
|
// A pinned topic reuses the taxonomy-archive path: same fixed-filter UI, same
|
|
// hidden input, same clear link, without needing an archive route.
|
|
$chrnx_pinned_slug = chrnx_validate_editorial_term_slug( $attributes['topic'] ?? '', 'chrnx_topic' );
|
|
$chrnx_pinned_term = '' !== $chrnx_pinned_slug ? get_term_by( 'slug', $chrnx_pinned_slug, 'chrnx_topic' ) : null;
|
|
$chrnx_pinned_term = $chrnx_pinned_term instanceof WP_Term ? $chrnx_pinned_term : null;
|
|
|
|
// Read-only filters do not change server state; every value is validated by the query service.
|
|
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
|
$chrnx_request = chrnx_get_journal_request_context( is_array( $_GET ) ? $_GET : array(), $chrnx_pinned_term );
|
|
$chrnx_args = chrnx_get_journal_query_args( $chrnx_request );
|
|
$chrnx_query = chrnx_run_eligible_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_show = chrnx_validate_editorial_term_slug( $chrnx_request['chrnx_show'] ?? '', 'chrnx_show' );
|
|
$chrnx_search = $chrnx_args['s'] ?? '';
|
|
$chrnx_form_url = chrnx_get_journal_base_url();
|
|
$chrnx_title_id = wp_unique_id( 'chrnx-journal-title-' );
|
|
$chrnx_fixed = chrnx_get_journal_archive_filter( $chrnx_pinned_term );
|
|
// A pinned stream is not the Journal; it is that topic's list, so it says so.
|
|
$chrnx_title = null !== $chrnx_pinned_term ? $chrnx_pinned_term->name : __( 'Journal', 'chrnx' );
|
|
?>
|
|
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-journal-stream' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> aria-labelledby="<?php echo esc_attr( $chrnx_title_id ); ?>">
|
|
<h<?php echo esc_attr( $chrnx_heading ); ?> id="<?php echo esc_attr( $chrnx_title_id ); ?>"><?php echo esc_html( $chrnx_title ); ?></h<?php echo esc_attr( $chrnx_heading ); ?>>
|
|
<form class="chrnx-journal-stream__filters" method="get" action="<?php echo esc_url( $chrnx_form_url ); ?>">
|
|
<?php if ( isset( $chrnx_fixed['taxonomy'] ) && 'chrnx_topic' === $chrnx_fixed['taxonomy'] ) : ?>
|
|
<p class="chrnx-journal-stream__fixed-filter"><span><?php echo esc_html__( 'Topic', 'chrnx' ); ?></span> <strong><?php echo esc_html( $chrnx_fixed['label'] ); ?></strong></p>
|
|
<input type="hidden" name="chrnx_topic" value="<?php echo esc_attr( $chrnx_fixed['slug'] ); ?>">
|
|
<?php else : ?>
|
|
<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>
|
|
<?php endif; ?>
|
|
<?php if ( isset( $chrnx_fixed['taxonomy'] ) && 'chrnx_language' === $chrnx_fixed['taxonomy'] ) : ?>
|
|
<p class="chrnx-journal-stream__fixed-filter"><span><?php echo esc_html__( 'Language', 'chrnx' ); ?></span> <strong><?php echo esc_html( $chrnx_fixed['label'] ); ?></strong></p>
|
|
<input type="hidden" name="chrnx_language" value="<?php echo esc_attr( $chrnx_fixed['slug'] ); ?>">
|
|
<?php else : ?>
|
|
<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>
|
|
<?php endif; ?>
|
|
<label>
|
|
<span><?php echo esc_html__( 'Search', 'chrnx' ); ?></span>
|
|
<input type="search" name="s" value="<?php echo esc_attr( $chrnx_search ); ?>">
|
|
</label>
|
|
<?php if ( ! empty( $chrnx_fixed ) ) : ?>
|
|
<a class="chrnx-journal-stream__clear" href="<?php echo esc_url( chrnx_get_full_journal_url() ); ?>"><?php echo esc_html__( 'View all Journal entries', 'chrnx' ); ?></a>
|
|
<?php endif; ?>
|
|
<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,
|
|
'chrnx_show' => $chrnx_show,
|
|
's' => $chrnx_search,
|
|
),
|
|
'strlen'
|
|
);
|
|
$chrnx_pages = array_unique(
|
|
array_filter(
|
|
array( 1, $chrnx_args['paged'] - 1, $chrnx_args['paged'], $chrnx_args['paged'] + 1, (int) $chrnx_query->max_num_pages ),
|
|
static function ( $chrnx_page ) use ( $chrnx_query ) {
|
|
return $chrnx_page >= 1 && $chrnx_page <= $chrnx_query->max_num_pages;
|
|
}
|
|
)
|
|
);
|
|
sort( $chrnx_pages, SORT_NUMERIC );
|
|
?>
|
|
<nav class="chrnx-journal-stream__pagination" aria-label="<?php echo esc_attr__( 'Journal pages', 'chrnx' ); ?>">
|
|
<ul class="page-numbers">
|
|
<?php foreach ( $chrnx_pages as $chrnx_page ) : ?>
|
|
<li>
|
|
<?php if ( $chrnx_page === $chrnx_args['paged'] ) : ?>
|
|
<span class="page-numbers current" aria-current="page"><?php echo esc_html( number_format_i18n( $chrnx_page ) ); ?></span>
|
|
<?php else : ?>
|
|
<a class="page-numbers" href="<?php echo esc_url( chrnx_get_journal_page_url( $chrnx_page, $chrnx_filter_args ) ); ?>"><?php echo esc_html( number_format_i18n( $chrnx_page ) ); ?></a>
|
|
<?php endif; ?>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</nav>
|
|
<?php endif; ?>
|
|
<?php else : ?>
|
|
<p class="chrnx-journal-stream__empty">
|
|
<?php echo esc_html__( 'No journal entries match these filters yet.', 'chrnx' ); ?>
|
|
<a href="<?php echo esc_url( chrnx_get_full_journal_url() ); ?>"><?php echo esc_html__( 'Browse the full Journal', 'chrnx' ); ?></a>
|
|
</p>
|
|
<?php endif; ?>
|
|
</section>
|