- This topic has 11 replies, 4 voices, and was last updated 1 year ago by Fernando.
-
AuthorPosts
-
October 21, 2021 at 4:01 am #1970518Karel
Hi,
I would like to change the excerpt length on the featured post only.
I tried the solution given here https://generatepress.com/forums/topic/longer-excerpt-on-featured-post/ but on my site it doesn’t seem to work.It could be that I’m doing something wrong since another code snippet from this topic https://generatepress.com/forums/topic/blog-add-on-different-number-of-post-in-first-page-of-blog/ is also not working on my site.
Thanks
October 21, 2021 at 4:22 am #1970543DavidStaffCustomer SupportHi there,
How are the Excerpts being created ? Are they a manual excerpt or is some other function generating them. As when i check the single post i cannot see that text in the content.
October 21, 2021 at 4:36 am #1970566KarelHi David,
These are normal automatic excerpts, not manual.
Not sure what you mean when you say you don’t see the text in the content, the excerpt is exactly the same as the first words of the post content and was generated automatically.The post was made sticky to make it the first post in the blog
In the customizer, the option “make first post featured” was turned onThanks for looking into it
October 21, 2021 at 4:55 am #1970597DavidStaffCustomer SupportSorry my bad … i am not sure what i was looking at 🙂
I done a quick test with a Sticky Post, the filter to change the number of posts on the first page, and the Excerpt length filter and it worked.
This is how my two functions look:
add_action( 'pre_get_posts', 'tu_change_posts_per_page', 1 ); function tu_change_posts_per_page( &$query ) { if ( ! is_main_query() ) { return; } if ( ! $query->is_paged ) { $query->set( 'posts_per_page', 15 ); // First page 15 posts } } add_filter( 'excerpt_length', 'tu_featured_excerpt_length', 50 ); function tu_featured_excerpt_length( $length ) { $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; global $wp_query; if ( 1 == $paged && 0 == $wp_query->current_post ) { return 100; // First post } return $length; }
October 21, 2021 at 5:04 am #1970602KarelThanks.
Can’t get it to work unfortunately.
I added your snippet in the extra CSS, but it has no effect, not the excerpt length and not on the nr of posts.
(Other modifications in the extra CSS do work)Not sure what I’m doing wrong…
October 21, 2021 at 5:56 am #1970632DavidStaffCustomer SupportAah… the code is PHP – this article explains how to add the code:
https://docs.generatepress.com/article/adding-php/
NOTE: If make sure you only add the functions once.
So if this code is working for changing the number of posts displayed:
https://generatepress.com/forums/topic/blog-add-on-different-number-of-post-in-first-page-of-blog/Then ONLY add the PHP provided here:
https://generatepress.com/forums/topic/longer-excerpt-on-featured-post/October 21, 2021 at 6:56 am #1970687KarelAh, of course…Sorry.
Both snippets work perfectly.
Thank you very much!October 21, 2021 at 7:13 am #1970705DavidStaffCustomer SupportReally glad to hear that!
March 19, 2023 at 2:19 pm #2573387OliverHey guys, this answer helped me with half my problem… the other half is this: how would I go about making the title of the featured post bigger than the rest?
March 19, 2023 at 5:43 pm #2573459Fernando Customer SupportHi Oliver,
Can you open a new topic with regard to the other issue?
March 20, 2023 at 1:49 am #2573748OliverNo problem. Here is the Link in case someone who´s interested lands in here
March 20, 2023 at 1:58 am #2573753Fernando Customer SupportThank you, Oliver! Let’s continue in the new thread.
-
AuthorPosts
- You must be logged in to reply to this topic.