27 lines
1.2 KiB
PHP
27 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* Related Posts block render.
|
|
*
|
|
* @package CHRNX
|
|
*/
|
|
|
|
$chrnx_post_id = isset( $block->context['postId'] ) ? absint( $block->context['postId'] ) : get_the_ID();
|
|
$chrnx_limit = isset( $attributes['limit'] ) ? min( 12, max( 1, absint( $attributes['limit'] ) ) ) : 3;
|
|
$chrnx_ids = chrnx_get_related_post_ids( $chrnx_post_id, $chrnx_limit );
|
|
if ( empty( $chrnx_ids ) ) {
|
|
return;
|
|
}
|
|
$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 );
|
|
$chrnx_title_id = wp_unique_id( 'chrnx-related-posts-title-' );
|
|
?>
|
|
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-related-posts' ) ); // 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__( 'Related stories', 'chrnx' ); ?></h<?php echo esc_attr( $chrnx_heading ); ?>>
|
|
<div class="chrnx-related-posts__grid">
|
|
<?php
|
|
foreach ( $chrnx_ids as $chrnx_related_id ) {
|
|
echo chrnx_get_editorial_card_markup( $chrnx_related_id, min( 6, $chrnx_heading + 1 ), 'chrnx-related-card' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
|
}
|
|
?>
|
|
</div>
|
|
</section>
|