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

7 Comments so far

  1. casino craps gambling

    January 8th, 2006

    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. new online casino

    January 8th, 2006

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


  3. pogo video poker

    January 12th, 2006

    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. […] Ah, y tengo que colver a escribir el la función para que los excerpts de mis feeds tengan formato […]


  5. […] Acabo de instalar el plugin Spam Karma para ver cómo me va para evitar la cantidad de comentarios de spam que he tenido últimamente. […]


  6. William Tobias

    January 29th, 2006

    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

    February 14th, 2006

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


Add yours

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