homegrade_blocks_production/blocks/post-content-container/build/render.php

25 lines
783 B
PHP

<?php
$relatedPostId = $attributes['relatedPostId'] ?? null;
$relatedPost = get_post($relatedPostId);
$anchor = !empty($attributes['anchor']) ? esc_html($attributes['anchor']) : "post-content-container-" . $attributes['relatedPostId'];
$content = get_the_content(null, null, $relatedPost);
if ($relatedPost) {
// Temporarily set up the global post variable so the_content works as expected
global $post;
$post = $relatedPost;
setup_postdata($post);
ob_start();
the_content();
$content = ob_get_clean();
wp_reset_postdata();
}
?>
<section id="<?php echo $anchor ?>" class="post-content-container <?php echo $anchor ? "has-custom-anchor" : "" ?>">
<h2 class="post-content-container__title"><?php echo $relatedPost->post_title ?></h2>
<?php echo $content; ?>
</section>