WordPress excerpt

Antonio hizo un comentario diciendo que los posts no salian completos en mi feed. Eso era por que en la configuración de WordPress indico que se muestre sólo una parte y no el post completo.

El asunto es que al hacer esto WordPress quitaba todas las imágenes, y formatos de el contenido del post. De ésta manera podía contar las palabras y mostrar únicamente las primeras 55, dejando texto sin formato y sin imágenes en el feed, que era de lo que se quejaba Antonio.

Busqué si había algun plugin que solucionara mi problema y que me permitiera tener resúmenes de post con formato, pero no encontré ninguno. Fuí al canal de #wordpress a preguntar pero tampoco me supieron dar razón :( .

Terminé nadando en el código fuente de WordPress siguiendo los archivos hasta llegar a la función que generaba el resumen, está en el archivo wp-includes/functions-formatting.php

function wp_trim_excerpt( $text ) { // Fakes an excerpt if needed
    global $post;
    if ( '' == $text ) {
        $text = $post->post_content;
        $text = strip_tags( $text );
        $blah = explode(' ', $text);
        $excerpt_length = 55;
        if (count($blah) > $excerpt_length) {
        $k = $excerpt_length;
        $use_dotdotdot = 1;
        } else {
        $k = count($blah);
        $use_dotdotdot = 0;
        }
        $excerpt = '';
        for ($i=0; $i<$k; $i++) {
        $excerpt .= $blah[$i].' ';
        }
        $excerpt .= ($use_dotdotdot) ? '[...]' : '';
        $text = $excerpt;
	        $text = $excerpt;
    } // end if no excerpt
    return $text;
}

Lo que hice fué cambiar la función para que use como resumen el primer párrafo (<p></p>) cambiando la función:

function wp_trim_excerpt( $text ) { // Fakes an excerpt if needed
    global $post;
    if ( '' == $text ) {
	$text = $post->post_content;
        //Only use the first paragraph
        $boob = explode('</p>', $text);
        if(count($boob) <= 2) {
        //There was less than two </p>s
            $excerpt = $text;
        } else {
        /*  There was a </p>, then the excerpt is
            the first line up to that </p>
        */
$excerpt = $boob[0]."</p>".$boob[1]."</p><p class="comment"><a href="".get_permalink($post->ID)."" title="".$post->post_title."">Continues...</a></p>";
        }
        $text = $excerpt;
    } // end if no excerpt
    return $text;
}

Puedo poner el link para que “Continues” a el respectivo permalink.

Cambiarla para que muestre mas de un párrafo es muy simple. Voy a probar como va con uno, sino le aumentaré :) .

Update: Cambié la función para que muestre dos párrafos y el “Continuar…” tenga vínculo al post

This entry was posted in programacion. Bookmark the permalink.

7 Responses to WordPress excerpt

  1. locked door kicked open The dust hadnt even cleared before Marty casino craps gambling Several hours later Marty was still talking about the evenings events .

  2. the radio off shaking his head in disgust new online casino Mr Arky .

  3. Inside the artillery bunker Captain Teague began to pass out pogo video poker being allowed inside This suburbian site was 15 miles from the blast .

  4. Pingback: Eso es ~normal! » Wordpress 2.0

  5. Pingback: Eso es ~normal! » Spam, Spam, Spam

  6. jacket had caught on the door jamb He tried frantically to get it onlkne casinos At the back of the class Biff and his group started to make farting .

  7. Reid Layton says:

    dad immediately turned away from the TV casino slot machine it for the third time The engine groanedbut then it caught! He .

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>