WordPress如何让文章只显示摘要

找到模板目录下的functions.php文件

添加:
function excerpt($num) {
    global $post;
    $content = apply_filters('the_content', get_the_content());
    $excerpt = strip_shortcodes(substr($content, 0, $num));
    $excerpt = apply_filters('wpautop', $excerpt);
    $excerpt = str_replace('[...]', '...', $excerpt);
    return $excerpt;
}

然后在你想要显示摘要的地方,使用以下代码来调用这个函数:

<?php the_excerpt(); ?>

本文摘自网络,不代表短经典网立场 https://www.duanjingdian.com/325.html

上一篇 2024 年 4 月 28 日 下午10:25
下一篇 2024 年 4 月 28 日 下午10:58

相关推荐