Every topic archive rendered its character art gate against the design master, which package-theme.sh deliberately strips, so production showed an empty stage on all eight of them. Gate on the derivative the markup actually loads instead. Nothing linked to a topic archive: the only filter was a select inside a form, invisible to crawlers and to anyone not looking for it. The stream now also lists the non-empty topics as links, marking the current one. Empty topics stay out, because a dead archive is worse than no link. Rank Math already owns the document head, so the theme's own og: tags were a second, conflicting set and core's title tag was a literal duplicate. Both now yield when an SEO plugin is active. Category archives listed the same posts as their topic at a second indexable URL. They now redirect to the same-slug topic, or the Journal. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
165 lines
8.1 KiB
PHP
165 lines
8.1 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 ); ?>>
|
|
<?php
|
|
/*
|
|
* The select below is invisible to crawlers and to anyone not hunting for it.
|
|
* These are the same filters as real links, so topics have an entry point.
|
|
* Empty topics stay hidden: a dead archive is worse than no link.
|
|
*/
|
|
$chrnx_topic_terms = get_terms(
|
|
array(
|
|
'taxonomy' => 'chrnx_topic',
|
|
'hide_empty' => true,
|
|
)
|
|
);
|
|
$chrnx_topic_terms = is_wp_error( $chrnx_topic_terms ) ? array() : $chrnx_topic_terms;
|
|
?>
|
|
<?php if ( count( $chrnx_topic_terms ) > 1 ) : ?>
|
|
<nav class="chrnx-journal-stream__topics" aria-label="<?php echo esc_attr__( 'Topics', 'chrnx' ); ?>">
|
|
<ul>
|
|
<li>
|
|
<a class="chrnx-journal-stream__topic" href="<?php echo esc_url( chrnx_get_full_journal_url() ); ?>"<?php echo '' === $chrnx_topic ? ' aria-current="page"' : ''; ?>><?php echo esc_html__( 'All', 'chrnx' ); ?></a>
|
|
</li>
|
|
<?php foreach ( $chrnx_topic_terms as $chrnx_term ) : ?>
|
|
<?php $chrnx_term_link = get_term_link( $chrnx_term ); ?>
|
|
<?php if ( ! is_wp_error( $chrnx_term_link ) ) : ?>
|
|
<li>
|
|
<a class="chrnx-journal-stream__topic" href="<?php echo esc_url( $chrnx_term_link ); ?>"<?php echo $chrnx_topic === $chrnx_term->slug ? ' aria-current="page"' : ''; ?>><?php echo esc_html( $chrnx_term->name ); ?></a>
|
|
</li>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</nav>
|
|
<?php endif; ?>
|
|
<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>
|