Open herregroen opened 3 years ago
Following for update on fix.
Nik @ntsekouras can you take a look?
Adding some additional info to this. When the Latest Posts block is set to show the "Full post", it does not actually render blocks on the frontend, hence the reason why dynamic blocks do not appear. If you look at the frontend markup, you will see all the block code, which is just rendered as HTML comments. See the screenshot below.
Similar issue reported on forum https://wordpress.org/support/topic/latest-posts-block-does-not-show-embeds/#post-15477750
I debugged it so I found the same reason described by @ndiego above.
Right one current code for full content it like this:
$list_items_markup .= sprintf(
'<div class="wp-block-latest-posts__post-full-content">%1$s</div>',
$post_content
);
But if I render the post content using the_content
filter, every thing is fine frontend but not in backend.
$post_content = apply_filters( 'the_content', str_replace( ']]>', ']]>', $post_content ) );
$list_items_markup .= sprintf(
'<div class="wp-block-latest-posts__post-full-content">%1$s</div>',
$post_content
);
WP Block Editor produces the same issue as it has similar code.
Also checking the edit.js for the latest posts, the raw
content is being set. that should be rendered
If I am not making any mistake understanding it.
{
displayPostContent && displayPostContentRadio === "full_post" && (
<div
className="wp-block-latest-posts__post-full-content"
dangerouslySetInnerHTML={{
__html: post.content.raw.trim(),
}}
/>
);
}
I am working on this issue, my above-proposed solution seems to work fine so far. If anyone finds any issue with those changes please let me know.
I have discovered a small problem while working on this issue.
Steps for the new issue.
You can't change it since min
is set to 2 and max
is dynamically set to posts max length.
If you'll type the value 1
in input then it will change and fallback to 2
It's so much to notice but some new users may find it problematic for them if they end in a similar situation when posts per page is 2
I tried to solve it by using useEffect
but I think that could be better way to handle this small thing.
This is what I used.
useEffect(() => {
const maxPossibleColumns = !hasPosts ? columns : Math.max(2, Math.min(columns, latestPosts.length));
if (postLayout === "grid") {
setAttributes({
columns: maxPossibleColumns,
});
}
}, [postLayout]);
So when columns=3
by default and postsLength=2
so we take minimum value then also set a fallback for when columns=1
so we take maximum between 2
and what we got from previous Min.
Description
The latest posts block does not render dynamic blocks when choosing to show the full post content.
This is especially jarring when you have posts whose content is entirely or primarily made up out of dynamic blocks, leading to a preview of no content.
Step-by-step reproduction instructions
Expected behaviour
I expected to see the full post content.
Actual behaviour
I see nothing.
Code snippet (optional)
The content is rendered here: https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/latest-posts/index.php#L147
the_content
filter should be applied here, although recursion of latest-posts blocks should be taken into account.WordPress information
Device information