Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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!

    #306686

    Hey 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ünter

    #344053

    Hi 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!

    #344871

    Hi!

    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,
    Elliott

    #344893

    Hi 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

    #344964

    Hi!

    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!
    Elliott

    #346787

    Hi 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!

    #347224

    Hey!

    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!
    Elliott

    #833630

    Hey, 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?

    #835572

    Hi,

    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

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.