• Resolved Graycode

    (@graycode)


    Hi All,

    I have looked for a solution to my problem and although i have seen code such as adding this to functions.php:

    function limit_words($string, $word_limit) {
    
    	// creates an array of words from $string (this will be our excerpt)
    	// explode divides the excerpt up by using a space character
    
    	$words = explode(' ', $string);
    
    	// this next bit chops the $words array and sticks it back together
    	// starting at the first word '0' and ending at the $word_limit
    	// the $word_limit which is passed in the function will be the number
    	// of words we want to use
    	// implode glues the chopped up array back together using a space character
    
    if (count($words) > $word_limit ) {$end = '…';}
    
    return implode(' ', array_slice($words, 0, $word_limit)). $end;
    }

    and this in my blog.php: ` <?php echo limit_words(get_the_excerpt(), ’10’); ?>
    `
    The link is https://test.akeytodesign.com/blog/

    Help is much appreciated!

    Thanks

Viewing 4 replies - 16 through 19 (of 19 total)
  • @anoodles: It is impolite to interrupt another poster’s ongoing thread with a question of your own. It causes significant problems for the forum’s volunteers and prevents us from being able to track issues by topic. Please post your own topic.

    I’m sorry guys i thought that because i wanted the exact opposite on the post thing that it would be considered relevant, that’s why i asked here… I won’t do it again ??

    Thread Starter Graycode

    (@graycode)

    Thanks…

    Does anyone have a solution to my last point so I can state this as ‘resolved’?

    Can you state how much of an excerpt you wish to display?

    Thread Starter Graycode

    (@graycode)

    Actually I have worked it out thanks to https://artarmstrong.com/blog/2011/01/02/how-to-modify-the_excerpt-in-wordpress/

    Put this in your functions.php and modify the 150 according to how much of the excerpt you wish to display.

    //Modify the length of the_excerpt
    function new_excerpt_length($length) {
    	return 150;
    }
    add_filter('excerpt_length', 'new_excerpt_length');
    
    //Modify the "Read More" link of the_excerpt
    function new_excerpt_more($more) {
    	$new = str_replace("Continue reading ", "Read More", $more);
    	$new = str_replace('<span class="meta-nav">→</span>', "", $new);
    	return $new;
    }
    add_filter('excerpt_more', 'new_excerpt_more');
Viewing 4 replies - 16 through 19 (of 19 total)
  • The topic ‘Difficulty limiting post excerpts’ is closed to new replies.