0

I need to change the character/word limit of manual excerpts which will be displayed on recent posts slider. I think it's 55 characters right now without counting spaces and punctuation marks. Am i right? I researched and accordingly tried to add some codes on functions.php but none of them worked. I thought they were out of date or unrelated. I also edited the following code in recent-posts-slider.php but didn't work:

$excerpt_length = 100;

Besides, how many words that recent posts slider shows isn't consistent anyway. It displays 10-15 words for a post then it displays properly 50 words for another.

What should i do?


You're right, i'm sorry. I'm just doing what i saw from some articles. I really don't know much about coding.

My 'recent posts slider' is a function that comes with the theme i use, called 'Big City'. So in themes/bigcity direction there is a recent-posts-slider.php file. I can set a 50 words limit for automated excerpts via wp-admin but couldn't set one for manuals.

I won't use excerpts in homepage, i just want those excerpts displayed in the slider. These are some codes about excerpts in recent-posts-slider.php :

    $excerpt_length = '';
$excerpt_length = abs( (($width-40)/20) * (($height-55)/15) );
/*if ( ($width) > $height)
$excerpt_length = $excerpt_length - (($excerpt_length * 5) /100);
else
$excerpt_length = $excerpt_length - (($excerpt_length * 30) /100);*/

function create_excerpt( $post_content, $excerpt_length, $post_permalink, $excerpt_words=NULL){
    $post_excerpt = strip_shortcodes($post_content);
    $post_excerpt = str_replace(']]>', ']]>', $post_excerpt);
    $post_excerpt = strip_tags($post_excerpt);
    $read_more = get_option_tree('blog_read', ''); 

    if( !empty($excerpt_words) ){   
        if ( !empty($post_excerpt) ) {
            $words = explode(' ', $post_excerpt, $excerpt_words );
            array_pop($words);
            if($read_more){
            array_push($words, ' <a href="'.$post_permalink.'">'.$read_more.'</a>');
            }
            else{
            array_push($words, ' <a href="'.$post_permalink.'"></a>');
            }
            $post_excerpt_rps = implode(' ', $words);
            return $post_excerpt_rps;
        } else {
            return;
        }
    }else{
        $post_excerpt_rps = substr( $post_excerpt, 0, $excerpt_length );
        if ( !empty($post_excerpt_rps) ) {
            if ( strlen($post_excerpt) > strlen($post_excerpt_rps) ){
                $post_excerpt_rps =substr( $post_excerpt_rps, 0, strrpos($post_excerpt_rps,' '));
            }   
            $words = explode(' ', $post_excerpt, $excerpt_words );
            array_pop($words);
            if($read_more){
            array_push($words, ' <a href="'.$post_permalink.'">'.$read_more.'</a>');
            }
            else{
            array_push($words, ' <a href="'.$post_permalink.'"></a>');
            }
            return $post_excerpt_rps;
        } else {
            return;
        }
    }
}
1
  • 1
    You have not provided enough information to answer any of your questions without guessing more or less wildly. What is in recent-posts-slider.php? What does the code do with $excerpt_length exactly? Without more context this is like trying to get help with an algebra problem by asking, "If x=100, how do I solve the equation?" Well, what is the equation?
    – s_ha_dum
    Commented May 5, 2013 at 18:50

1 Answer 1

1

The line below the one you edited computes the edited words based on the height and width of the slider box. The value you added is changed on the next line. Avoid editing the plugin file. Next time you update the plugin your changes will be lost.

You should be able to change the Excerpt length on the plugin options page on the Excerpt Words option. Apparently, the Excerpt Words option overrides the computed $excerpt_length value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.