dousou2897 2016-11-15 07:06
浏览 82
已采纳

wordpress自定义摘录长度不起作用

I have this code in my functions.php

function custom_excerpt_length() {

return 15;

}

add_filter('excerpt_length', 'custom_excerpt_length');

but it doesn't work as it gives me the full text and not the 15 words I specified. And the grid I have set up on my website is not right because of this.

my movie grid

Thanks in advance

  • 写回答

2条回答 默认 最新

  • dongping1012 2016-11-15 07:20
    关注

    Also use this code for multiple type of getting excerpt

    function excerpt($limit) {
          $excerpt = explode(' ', get_the_excerpt(), $limit);
          if (count($excerpt)>=$limit) {
            array_pop($excerpt);
            $excerpt = implode(" ",$excerpt).'...';
          } else {
            $excerpt = implode(" ",$excerpt);
          } 
          $excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
          return $excerpt;
        }
    
        function content($limit) {
          $content = explode(' ', get_the_content(), $limit);
          if (count($content)>=$limit) {
            array_pop($content);
            $content = implode(" ",$content).'...';
          } else {
            $content = implode(" ",$content);
          } 
          $content = preg_replace('/\[.+\]/','', $content);
          $content = apply_filters('the_content', $content); 
          $content = str_replace(']]>', ']]>', $content);
          return $content;
        }
    

    then in your template code you just use..

    <?php echo excerpt(25); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功