截取可以用wp_trim_words()

用法:

<?php $trimmed = wp_trim_words( $text, $num_words = 55, $more = null ); ?>

参数说明:$text---截取内容,$num_words ---限定字数,$more ---截取后加在尾部的字符

 

截取文章内容:

<?php
    $content = get_the_content();
    $trimmed_content = wp_trim_words( $content, 40, '<a href="'. get_permalink() .'"> ...Read More</a>' );
    echo $trimmed_content;
?>

截取文章标题:

<?php
    $title = get_the_title();
    $trimmed_title = wp_trim_words( $title, 20, '...' );
    echo $trimmed_title;
?>

 

相关文章:

  • 2022-01-01
  • 2021-12-22
  • 2022-12-23
  • 2021-05-31
  • 2021-12-22
  • 2021-09-15
  • 2022-02-08
  • 2021-12-22
猜你喜欢
  • 2022-01-08
  • 2021-11-26
  • 2021-08-01
  • 2022-01-01
  • 2021-12-22
  • 2021-09-08
相关资源
相似解决方案