PHP Question

Out of context: Reply #6

  • Started
  • Last post
  • 11 Responses
  • acescence0

    a couple changes from the post above- the_excerpt will always echo the text, you can't assign it to a var like that. you either need to buffer output or use get_the_excerpt.
    if you do it by character using substr, you'll end up with parts of words instead of only whole words..

    $string = get_the_excerpt();
    $words = explode(' ', $string);
    $string = implode(' ', array_slice($words, 0, 10)); // 10 = number of words
    echo $string;

    • yes , I was uneasy about the_excerpt(); not sure what it's made offBattleAxe

View thread