Site logo

Archived topic

Automatic excerpts and the manual "Read More" tags looping in harmony.

16 replies · Started by twarrior on September 8, 2022

Viewing posts 1–15 of 17

Hello,

Through GB support, I got a partial solution to my problem.

I expose it all here to see if a "complete" solution is possible.

THE INITIAL PROBLEM

I was using WP Show Post. Trying now to switch to Query Loop blocks....

We have SOME posts with the "more" tag included manually, and some not.

With "WP Show Post", when you tell it to show the automatic "excerpt" (x number of characters), it follows two steps:

1st) if the post has a manually included "read more", it gives priority to the "read more" (it uses the manually chosen intro text) and also shows the word formatting (bold, links, paragraph breaks, etc.).
2nd) if the post does not have a read more, then it automatically generates the extract with x number of characters.

But with Query Loop we only get the automatic "extract" with the given number of characters, and the text is not formatted.

How to do with Query Loop what WP Show Post does?

THE ANSWER FROM GB SUPPORT

1. Add a "Headline Block", and in "Dynamic options" choose "Excerpt".

2. Add this PHP code, so when it detects the "more" tag, the "GB headline block" will output the content instead.

add_filter( 'generateblocks_dynamic_content_output', function( $output, $attributes ) {
    if ( 'post-excerpt' === $attributes['dynamicContentType'] ) {
        global $post;

        if ( strpos( $post->post_content, '<!--more-->' ) ) {
            $output = get_the_content();
        }
    }

    return $output;
}, 10, 2 );

THE "LITTLE" PROBLEM

The code works quite well, but... when a post has the tag "more", the "read more" button appears twice (the one created in the querry loop and the automatic one of the post itself) (see photo and link)

https://share.getcloudapp.com/NQujZZk4

any solutions for a lover of the "more" tag?

THANKS IN ADVANCED, AND CONGRATULATIONS FOR YOR PLUGINS AND TEMPLATE

PD: A personal reflection on the margin of the problem: in your wonderful plugins and template (and I think in wordpress in general), I get the feeling that the "excerpt" is used more and more, and few (or no) options are given to control the posts with the "more" tag. If there was at least the option to show the excepts "with formatting" (bold, line breaks, etc.), we would use them more... but nothing like being able to control what is shown using the "more" tag ;-)

Hello there,

Thanks for the input. We appreciate it.

How about hiding the more tag button through CSS? Try adding this in Customize > Additional CSS:

p.read-more-container {
    display: none;
}

Does this work?

Thanks, but in that case if someone accesses a category view, the "read more" button does not appear.

Hi there,

you can target the just the query loop wrapper like so:


.gb-query-loop-wrapper p.read-more-container {
    display: none;
}

Does that work ?

Thank you. It works! But just a small "critique":

GB + css code + a code snippet... to get something that "WP Show Post" already does ?!

If possible, put more (or some) integration of the "more" tag together with the "automatic Excerpt" options in your roadmap ;-)

We'll take a look at whats possible, i believe there are some limitations as to what we can do within the editor, so previews may not be exact. But ill add it to our Git issues :)

Thank you very much for listening to me.
Thank you very much for taking it into account.
Thank you very much for being the best support service I know.
If I can help in any way, at tester level or whatever, count on me.

Thanks for the above code to output Dynamic Content when the <!--more--> tag is used. Super helpful!

My question - is there any further code we can add to change the "Read More" button to text instead, or simply remove the button altogether? Like in this screenshot:

https://www.screencast.com/t/vFMA41VXH2

We can use CSS to try and change the button back to text only, but that would be messier and risks the chance that the button would flash quickly before the CSS finished loading and it was then changed to text.

Thanks!

Hi Vico,

You'll still need to use the custom CSS provided above by David to hide the Read More link/button. If it isn't working, can you provide the link to the site in question?

Ok, thanks. Understood. We'll use the default "Read More" button to simplify things then.

You're welcome VR!

Hello - We're back.

Two more questions:

1) Is there a way to adapt the code above (post #2337324) to also work for the default Search Results post excerpts? They don't use the "GB Headline block" so the code doesn't work for them.

Know we can create a whole new Search Results template, per https://generatepress.com/forums/topic/design-search-page/, but since the only change we need is displaying dynamic excerpts when the <!--more--> link exists in the post content, would rather not have to create a whole new template to achieve that.

2) For static WP Pages - Is it possible to add a snippet to also include an auto-generated excerpt on the Search Results page? Or, will the client need to add a manual custom excerpt if they want text to appear for Pages, too?

Thanks!

1. For reference, can you re-share the link to the site in question?
2. They should be included by default. We'll check your search page first once you've shared the link.

Thanks. Because this is a reply to the original support thread created by another use, I don't see an option to include the URL privately.

Instead, if you check the private link we provided on the below thread - it should have the site URL.

- Post ID 2355797: https://generatepress.com/forums/topic/category-terms-display-issue-in-query-loop-gp-block/

To see the Search Results page, just append "/?s=meetings#" to the end of the main URL. You'll see the 2nd item, the "About" page, does not display any excerpt content even though there is content on the page itself.

Thanks

This archived topic is closed to new replies.