cut text after (x) amount of characters

后端 未结 5 1574
谎友^
谎友^ 2021-01-13 07:03

This is in wordpress (not sure that makes a difference)

This bit of php outputs the post title


         


        
5条回答
  •  时光说笑
    2021-01-13 07:26

    in your theme file use something like this try using

    then in the functions.php files, use this

    function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '')
     {
    
        $content = get_the_content($more_link_text, $stripteaser, $more_file);
        $content = apply_filters('the_content', $content);
        $content = str_replace(']]>', ']]>', $content);
        $content = strip_tags($content);
    
       if (strlen($_GET['p']) > 0) 
    {
    
          echo "
    "; echo $content; echo "
    "; } else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) { $content = substr($content, 0, $espacio); $content = $content; echo "
    "; echo $content; echo "..."; echo "
    "; } else { echo "
    "; echo $content; echo "
    "; } }

    good luck :)

提交回复
热议问题