- This topic has 16 replies, 5 voices, and was last updated 5 months ago by
VR.
-
AuthorPosts
-
September 8, 2022 at 11:19 am #2337324
twarrior
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 π
September 8, 2022 at 9:34 pm #2337583Fernando Customer Support
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?
September 9, 2022 at 2:30 am #2337787twarrior
Thanks, but in that case if someone accesses a category view, the “read more” button does not appear.
September 9, 2022 at 8:24 am #2338216David
StaffCustomer SupportHi 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 ?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/September 9, 2022 at 9:34 am #2338300twarrior
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 π
September 12, 2022 at 3:07 am #2340314David
StaffCustomer SupportWe’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 π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/September 12, 2022 at 3:26 am #2340338twarrior
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.September 12, 2022 at 6:08 am #2340443David
StaffCustomer SupportWe try π
I opened a Git Issue here – feel free to comment or track its progress:https://github.com/tomusborne/generateblocks/issues/693
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 10, 2022 at 3:27 pm #2369265VR
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:
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!
October 10, 2022 at 7:34 pm #2369367Fernando Customer Support
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?
October 15, 2022 at 9:04 am #2374598VR
Ok, thanks. Understood. We’ll use the default “Read More” button to simplify things then.
October 16, 2022 at 5:03 pm #2375677Fernando Customer Support
You’re welcome VR!
October 18, 2022 at 3:15 pm #2378101VR
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!
October 18, 2022 at 5:48 pm #2378180Fernando Customer Support
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.October 19, 2022 at 7:31 am #2378722VR
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
-
AuthorPosts
- You must be logged in to reply to this topic.