Función muy completa para cuando queremos personalizar un poco el listado de post del archive.php o index.php de nuestro wordpress, y que debemos incluir en nuestro functions.php. Con ella podemos personalizar el número de caracteres por post, así como el texto del link (‘Leer mas…, Read more, Seguir, etc…’)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | function wp_limit_post($max_char, $more_link_text = '[...]',$notagp = false, $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) { if($notagp) { echo substr($content,0,$max_char); } else { echo '<p>'; echo substr($content,0,$max_char); echo "</p>"; } } else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) { $content = substr($content, 0, $espacio); $content = $content; if($notagp) { echo substr($content,0,$max_char); echo $more_link_text; } else { echo '<p>'; echo substr($content,0,$max_char); echo $more_link_text; echo "</p>"; } } else { if($notagp) { echo substr($content,0,$max_char); } else { echo '<p>'; echo substr($content,0,$max_char); echo "</p>"; } } } |
1 2 | // Modo de uso: wp_limit_post(180,'...',true); |
