adapting post-content-container render to handle inner render.php

This commit is contained in:
Antoine M 2024-07-02 16:12:30 +02:00
parent 78d9480dca
commit d89e334aa3
3 changed files with 31 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@ -2,10 +2,24 @@
$relatedPostId = $attributes['relatedPostId'] ?? null;
$relatedPost = get_post($relatedPostId);
$anchor = isset($attributes['anchor']) ? esc_html($attributes['anchor']) : "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 $relatedPost->post_content ?>
<?php echo $content; ?>
</section>

View File

@ -2,10 +2,24 @@
$relatedPostId = $attributes['relatedPostId'] ?? null;
$relatedPost = get_post($relatedPostId);
$anchor = isset($attributes['anchor']) ? esc_html($attributes['anchor']) : "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 $relatedPost->post_content ?>
<?php echo $content; ?>
</section>