-
AuthorPosts
-
August 20, 2014 at 9:10 am #306664
Hi there,
Great theme!
How do I set the excerpt limit for blog posts in the category view?
Most of the posts are showing almost the whole post, which takes up a lot of space.Is there a way for me to set the category views to only display the first 500 characters or 100 words, etc?
Also, is there a way to show the excerpts without html?
Thank you!
August 20, 2014 at 10:28 am #306686Hey foxvendetta!
Thank you for using our theme.
Try to put the following code in functions,php (preferred is of your child theme) and adjust the number of length:
function custom_excerpt_length( $length ) { if(is_category()) { $length = 30; } return $length ; } add_filter( 'excerpt_length', 'custom_excerpt_length', 999, 1 );
Best regards,
GünterOctober 31, 2014 at 3:17 pm #344053Hi Gunter!
I am also trying to do this (limit the length in category view), and I tried entering the above code in functions.php but it didn’t work. Is there a new suggestion with the latest theme update that is perhaps different? Thanks!
November 2, 2014 at 4:15 pm #344871Hi!
Try adding this to the bottom of your
/enfold/functions.php
file.function custom_category_excerpt( $c ) { if ( is_category() ) { return substr( get_the_content(), 0, 200 ); } return $c; } add_filter( 'the_content', 'custom_category_excerpt', 999, 1 );
Regards,
ElliottNovember 2, 2014 at 5:16 pm #344893Hi Elliott!
Thank you! Unfortunately this code seems to have crashed the entire site, giving the following error:
Parse error: syntax error, unexpected $end, expecting T_STRING or T_VARIABLE or ‘$’ in /themes/enfold-child/functions.php on line 35
November 2, 2014 at 7:54 pm #344964Hi!
Are you sure your adding it to the end of the file? Try uploading a fresh copy of the file and add it to the very bottom.
Cheers!
ElliottNovember 5, 2014 at 10:19 pm #346787Hi Elliot, Thanks it worked!
Unfortunately what happens when truncating the text is that the image code shows up as text, so for example…after the title of a post it reads “[caption id="attachment_6128" align="alignright" width="300"]…. with the text entry. To a reader, it looks like a bunch a gibberish.
I think given that, it will be better to just list the whole entire article.
It would be great to see a feature similar truncated feature to magazine or blog post if possible in a future update. Thank you!
November 6, 2014 at 6:17 pm #347224Hey!
This should strip the shortcodes out.
function custom_category_excerpt( $c ) { if ( is_category() ) { return substr( strip_shortcodes(get_the_content()), 0, 200 ); } return $c; } add_filter( 'the_content', 'custom_category_excerpt', 999, 1 );
Cheers!
ElliottAugust 2, 2017 at 9:42 pm #833630Hey, thanks so much — Günter’s code is working for me on posts using the default editor, but not on posts using the ALE (Advanced Layout Editor) — is there a snippet I can add so excerpts for posts using the ALE are also limited in length?
August 7, 2017 at 7:40 pm #835572Hi,
You can add the same function for the_excerpt which is used on ALB and it will do work properly.
Let us know if you would have any issues.
Best regards,
Basilis -
AuthorPosts
- You must be logged in to reply to this topic.