Files
chrnx-dev-wp/blocks/topic-hero/render.php
T
chrnxandClaude Opus 5 f9191a18bc fix: make topics reachable and stop the head fighting itself
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>
2026-08-14 08:43:16 -05:00

56 lines
2.9 KiB
PHP

<?php
/**
* Topic Hero block render.
*
* @package CHRNX
*/
$chrnx_topic = isset( $attributes['topic'] ) && is_string( $attributes['topic'] ) ? $attributes['topic'] : '';
if ( '' !== $chrnx_topic && ! preg_match( '/^[a-z0-9]+(?:-[a-z0-9]+)*$/', $chrnx_topic ) ) {
return;
}
$chrnx_queried = get_queried_object();
$chrnx_taxonomy = '';
if ( '' === $chrnx_topic && $chrnx_queried instanceof WP_Term && in_array( $chrnx_queried->taxonomy, array( 'chrnx_topic', 'chrnx_show' ), true ) ) {
$chrnx_topic = $chrnx_queried->slug;
$chrnx_taxonomy = $chrnx_queried->taxonomy;
}
if ( '' === $chrnx_topic ) {
return;
}
$chrnx_art_topic = 'chrnx_show' === $chrnx_taxonomy ? 'podcasts' : $chrnx_topic;
$chrnx_asset = chrnx_get_topic_art_asset( $chrnx_art_topic );
$chrnx_size = chrnx_get_topic_art_dimensions( $chrnx_art_topic );
$chrnx_has_art = '' !== $chrnx_asset && 2 === count( $chrnx_size );
/*
* The packaged theme ships only assets/images/generated, so the design master
* is absent in production and gating on it hid the art on every topic archive.
* Check the derivative the markup actually loads.
*/
$chrnx_has_image = $chrnx_has_art && is_readable(
get_theme_file_path( 'assets/images/generated/' . pathinfo( $chrnx_asset, PATHINFO_FILENAME ) . '-768.webp' )
);
$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 );
$chrnx_term = $chrnx_queried instanceof WP_Term && $chrnx_queried->slug === $chrnx_topic ? $chrnx_queried : get_term_by( 'slug', $chrnx_topic, 'chrnx_topic' );
$chrnx_label = $chrnx_term instanceof WP_Term ? $chrnx_term->name : ucwords( str_replace( '-', ' ', $chrnx_topic ) );
$chrnx_classes = 'chrnx-topic-hero is-topic-' . sanitize_html_class( $chrnx_topic );
$chrnx_wrapper = isset( $block ) && $block instanceof WP_Block ? get_block_wrapper_attributes( array( 'class' => $chrnx_classes ) ) : 'class="' . esc_attr( $chrnx_classes ) . '"';
?>
<section <?php echo $chrnx_wrapper; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Generated by block supports or escaped above. ?>>
<div class="chrnx-character-stage">
<div class="chrnx-character-stage__atmosphere" aria-hidden="true">
<?php if ( ! $chrnx_has_image ) : ?>
<span class="chrnx-topic-hero__fallback" aria-hidden="true"></span>
<?php endif; ?>
</div>
<div class="chrnx-character-stage__content 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-character-stage__art chrnx-topic-hero__art">
<?php if ( $chrnx_has_image ) : ?>
<?php echo chrnx_get_topic_portrait_markup( $chrnx_art_topic, '', 'chrnx-section-portrait', 'eager' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?>
<?php endif; ?>
</div>
</div>
</section>