Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将摘录长度从55减少到我想要的值_Php_Wordpress - Fatal编程技术网

Php 如何将摘录长度从55减少到我想要的值

Php 如何将摘录长度从55减少到我想要的值,php,wordpress,Php,Wordpress,有人能告诉我如何处理will上的内容以尽可能少地显示内容吗?…在functions.php中添加了以下代码 function custom_excerpt_length( $length ) { return 20; } add_filter( 'excerpt_length', 'custom_excerpt_length', 999 ); 函数摘录($limit){ $EXECRPT=爆炸(“”,获取_EXECRPT(),$limit); 如果(计数($摘录)>=$l

有人能告诉我如何处理will上的内容以尽可能少地显示内容吗?…

在functions.php中添加了以下代码

  function custom_excerpt_length( $length ) {
   return 20;
   }
   add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
函数摘录($limit){
$EXECRPT=爆炸(“”,获取_EXECRPT(),$limit);
如果(计数($摘录)>=$limit){
数组_pop($摘录);
$EXECRPT=内爆(“,$EXECRPT)。”;
}否则{
$execrpt=内爆(“,$execrpt);}$execrpt=preg\u replace(“\[^\]*\]”,“,$execrpt”);
返回$摘录;
} 
无论在何处使用,只需添加

您需要提供更多详细信息。有点不清楚你想实现什么…这是一个wordpress页面,有帖子,在侧边栏中我想显示一些帖子的有限内容…你应该在标签中包含wordpress,并在帖子中添加一些细节。更新后的结果是确定的…???得到了我的答案…解决方案如下。。。。。。
  function custom_excerpt_length( $length ) {
   return 20;
   }
   add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
      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; 
       } 
       and wherever to use just add 
       <?php echo $excerpt(What_length_you_want);?>