Files
chrnx-dev-wp/blocks/related-posts/render.php
T

26 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 );
?>
<section <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-related-posts' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> aria-labelledby="chrnx-related-posts-title-<?php echo esc_attr( $chrnx_post_id ); ?>">
<h<?php echo esc_attr( $chrnx_heading ); ?> id="chrnx-related-posts-title-<?php echo esc_attr( $chrnx_post_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>