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/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"
|
||||
}
|
||||
@@ -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>
|
||||
Reference in new issue
Block a user