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

30 lines
1.1 KiB
PHP

<?php
$relatedPostId = isset($attributes['relatedPostId']) ? $attributes['relatedPostId'] : null;
if (!$relatedPostId) return;
$relatedPost = get_post($relatedPostId) ?? null;
$anchor = isset($attributes['anchor']) && !empty($attributes['anchor']) ? esc_html($attributes['anchor']) : "post-content-container-" . $attributes['relatedPostId'];
$anchor = isset($attributes['anchor']) && !empty($attributes['anchor']) ? esc_html($attributes['anchor']) : ($relatedPostId ? "post-content-container-" . $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; ?> -->
<?php echo $relatedPost->post_content ?>
</section>