Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* limita a quantidade de caracteres do excerpt - deve ser colocado no arquivo functions.php */
- function limitatexto($texto, $final, $limite){
- $result = $texto;
- $len_texto = strlen($texto);
- $len_final = strlen($final);
- if ($len_texto + $len_final > $limite){
- for ($i=$limite-$len_final;$i!==-1;$i--){
- if (substr($texto, $i, 1) == " " and substr($texto, $i-1, 1) !== " "){
- return substr($texto, 0, $i).$final;
- break;
- }
- }
- }
- return $texto;
- }
- ?>
- <?php //MODO DE USAR: no template, onde quer que seu texto seja afetado...?>
- <?php
- //Ao invés de usar <?php the_excerpt()?>, vamos usar "get_the_excerpt()" ....
- $excerpt = get_the_excerpt();
- echo limitatexto( $excerpt, '[...]', 80); //80 é a quantidade de caracteres...
- ?>
- <a href="<?php the_permalink()?>">Leia mais »</a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement