WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.46k stars 4.18k forks source link

FSE: post-content block appears like post-excerpt and vice-versa #27214

Open bobbingwide opened 3 years ago

bobbingwide commented 3 years ago

Describe the bug When the post-content and post-excerpt blocks are displayed in the post-content of a post displayed in a query block the output doesn't match expectations, neither in the editor nor the front end.

To reproduce Steps to reproduce the behavior:

  1. Create a post with the highest title - eg Zzz as below
  2. Create a page that runs the query to display the post created in step 1 - also as below
  3. View the results in the front end and the editor.
  4. Notice that they don't match expectations.

The content of the post with the highest title ( Zzz ) is

<!-- wp:paragraph -->
<p>Zzz - post excerpt before more.</p>
<!-- /wp:paragraph -->

<!-- wp:separator -->
<hr class="wp-block-separator"/>
<!-- /wp:separator -->

<!-- wp:more -->
<!--more-->
<!-- /wp:more -->

<!-- wp:paragraph -->
<p>Zzz - start of post content after more. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This post was created to test post content &amp; post excerpt extraction for the <code>core/post-content</code> and <code>core/post-excerpt</code> blocks when they're inner blocks of the <code>core/query</code> <code>core/query-loop</code> constructs. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>See <a href="https://s.b/wp56/aaf/">page Aaf</a>.</p>
<!-- /wp:paragraph -->

The content of page Aaf is

<!-- wp:paragraph -->
<p>aaf's post excerpt before more.</p>
<!-- /wp:paragraph -->

<!-- wp:query {"queryId":1,"query":{"perPage":1,"pages":1,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"title","author":"","search":"","exclude":[1346],"sticky":""},"className":"border"} -->
<!-- wp:query-loop -->
<!-- wp:post-title {"isLink":true} /-->

<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:heading {"level":3} -->
<h3>Post content</h3>
<!-- /wp:heading -->

<!-- wp:post-content /--></div>
<!-- /wp:column -->

<!-- wp:column -->
<div class="wp-block-column"><!-- wp:heading {"level":3} -->
<h3>Post excerpt</h3>
<!-- /wp:heading -->

<!-- wp:post-excerpt {"wordCount":43,"showMoreOnNewLine":false} /--></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
<!-- /wp:query-loop -->
<!-- /wp:query -->

<!-- wp:more -->
<!--more-->
<!-- /wp:more -->

<!-- wp:paragraph -->
<p>aaf's post content after more.</p>
<!-- /wp:paragraph -->

Expected behavior

For the display of the post created in Step 1.

Block Where Result
Post content Front end The full post content should be displayed, there shouldn't be a more link
Post excerpt Front end It should contain the post excerpt, with a more link
Post content Editor The full content should be displayed as on the front end. It shouldn't be possible to interact with the blocks. There shouldn't be a message about using more than one More block.
Post excerpt Editor It should only display the post excerpt, before the More block.

Further notes regarding the post excerpt.

In my opinion the logic to display the post excerpt should be the same as the logic to display the post content. The word limit should only be applied when the post excerpt has not been explicitely defined, either by the More block or by it being manually created.

Post excerpt processing should include:

Screenshots Here's the result where page Aaf uses a query to display the last post in two columns with Post content on the left and Post excerpt on the right. The Post content looks more like that which I'd expect the Post excerpt should look. The Post excerpt should display the more link.

image

In the block editor the display is more confusing. image

Expected result - front end - Post content

image

Editor version (please complete the following information):

Desktop (please complete the following information):

Additional context

In order to get the expected result on the front end for the Post content I found that I needed to change the core function get_the_content() ( wp-includes\post-template.php ) adding one line of code

C:\apache\htdocs\wp56>git diff wp-includes\post-template.php
diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php
index 0aff64d..a71a170 100644
--- a/wp-includes/post-template.php
+++ b/wp-includes/post-template.php
@@ -327,6 +327,7 @@ function get_the_content( $more_link_text = null, $strip_teaser = false, $post =
                if ( has_block( 'more', $content ) ) {
                        // Remove the core/more block delimiters. They will be left over after $content is split up.
                        $content = preg_replace( '/<!-- \/?wp:more(.*?) -->/', '', $content );
+            $elements['more'] = true;
                }

                $content = explode( $matches[0], $content, 2 );

I haven't checked to see if there's a WordPress TRAC.

joyously commented 3 years ago

I think you have faulty expectations of how the more tag works. Core WP returns the correct amount of content according to the more tag's options and the page that is requested. The more tag is rendered only on archive requests of full content posts. So your test case should not show any more tags, since it's on a Page.

bobbingwide commented 3 years ago

So your test case should not show any more tags, since it's on a page.

My expected result ( 3rd screen shot ) does not show a more tag for the Post content column. I expect the full content of the post ( Zzz ) to be displayed.

The first screen shot shows the More tag I don't want to see and doesn't display the content after the more tag.

With regards to the Post Excerpt. Here I do expect the more tag to be displayed on the front end. Additionally I expect HTML tags in the excerpt to be respected, not stripped.

joyously commented 3 years ago

The first screen shot shows the More tag I don't want to see and doesn't display the content after the more tag.

This is how more tags work, but it shouldn't actually be showing because it's not an archive page (although the query might be considered an archive query).

With regards to the Post Excerpt. Here I do expect the more tag to be displayed on the front end.

The more tag has nothing to do with the excerpt. The more tag is only rendered when showing full content on an archive page.

Additionally I expect HTML tags in the excerpt to be respected, not stripped.

If you write a manual excerpt, the HTML won't be stripped. HTML tags are stripped when generating automatic excerpts.

bobbingwide commented 3 years ago

@joyously There's a subtle difference between "What do I expect" and "What do I want". I've been using a shortcode that I wrote for longer than I can remember.

This is the output using the following shortcode

[bw_table post_type=post numberposts=1 orderby=title order=desc fields=title,content,excerpt]

to create the equivalent of what I expected. image

Being so used to this sort of output I expected to get the same results from core/post-content and core/post-excerpt. So, I'll rephrase this as "What I want" or "What I would like to have happen".

Post content requirements

Post excerpt requirements

I believe these are reasonable requirements.

It would appear to me that the core/post-excerpt block, as currently implemented, neither satisfies this requirement nor delivers what it promises with regard to the Show link on new line toggle.

P.S. I've just discovered that updating the post excerpt of one post while it's being viewed from another actually updates the excerpt. Wacky.

carolinan commented 3 years ago

Hi @bobbingwide, I am working on the post excerpt block, are there any actionable items left in this issue?

The post excerpt block does not use the more tag. It has a placeholder text for the read more link, and if this placeholder text is not replaced, it does not output a read more link text. -The block can not show a link on a new line if there is no link.

It also does not prevent other content from showing. If you have a post template or post query that uses the content block, and you add the post excerpt block in the block editor, it will show a custom or automated excerpt, but if there are other blocks in the post, those will also show.

bobbingwide commented 3 years ago

Hi Carolina, I restated my requirements in my most recent comment ( November ).

How I envisage the Excerpt being created automatically, when there isn't a hand written one, is that it would be the content prior to the more tag.

This is the excerpt. It may have <b>HTML</b> and all sorts of other stuff such as links, images, fancy blocks doing wierd things and dare I say it, inline shortcodes.
<!-- more -->
This is the rest of the content.

In my shortcodes, when extracting the excerpt, my code respected the HTML, images etc. I had an option to display the "read more" link after the excerpt.

When I displayed the full content, then there was no reason to display a read more link.

One use case would be a grid of 3 posts of post type "block", displaying the block's SVG first followed by the block's description, then, a read more button.

Another use case is demonstrated here: https://blocks.wp-a2z.org/oik-plugins/gutenberg/?oik-tab=blocks

These are variations of excerpt that aren't currently catered for by WordPress core.
Perhaps there should be a variation called Teaser.

jeiseman commented 1 year ago

I added the code in the following attachment to get this to work the way I expect.

getexcerpt.txt

If the 'read-more' tag is used it will leave images in and display everything up to the "read-more" (followed by a link to read more) otherwise it will return the excerpt followed by a read-more link. It would be good if this could be done directly with the Post Excerpt block instead of requiring the need to add the filter.