首页 文章

修剪用户在content.php wordpress文件中输入了摘录

提问于
浏览
0

我有一个自定义功能来修剪摘录:

function custom_excerpt_length( $length ) {
return 10; }

以及应用它的过滤器:

add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

然后我在我的content.php中得到摘录:

<?php the_excerpt(); ?>

如果未找到自定义用户输入的摘录,则该功能有效 . 所以基本上从博客文章内容中抓取前10个单词 . 但是当我自定义输入摘录时它不会修剪 . 显示用户剪裁版本的任何想法都在博客帖子页面中摘录了?

1 回答

  • 0

    我终于得到了我需要的东西 . 所以我只想将修剪过的摘录减少到较低的字符数 . 我刚刚添加到我的功能页面:

    function custom_excerpt_more( $more ) {
        $more = '&hellip;';
        return $more; 
    }
    add_filter( 'excerpt_more', 'custom_excerpt_more' ); //displays ... after the excerpt
    
    function custom_excerpt_length( $length ) {
    return 30; //number of words to display in the excerpt
    }
    add_filter( 'excerpt_length', 'custom_excerpt_length', 999 ); //999 si it filters at the end
    

    然后在我的content.php页面中:

    <p><?php echo substr(get_the_excerpt(),0,80);?></p>
    

    这样,我的博客帖子列表页面中的字符数不超过80个,个人博客帖子页面上的字数不超过30个(content-single.php) .

相关问题