Pregunta

¿Cómo puede tener de manera que la página principal del sitio sólo mostrará el primer X (digamos 300) palabras del mensaje?

Sin embargo, sin el uso de extractos "más" etiqueta, o la mano llenaron? Busco un plugin / truco para WP 2.9 y en adelante.

Me encontré con varias soluciones hasta ahora, pero estoy esperando una solución recomendada.

Los retos me llegó una cruz hasta el momento:

  • ¿Qué ocurre en el caso de una etiqueta (por ejemplo) se inicia en la palabra 295, y termina después de la palabra 301?
  • ¿Puede ser posible tener un X diferente para la página principal, página de etiquetas, página de categoría - y así sucesivamente
  • se puede conservar el formato del texto? (Todas las imágenes y formateo de texto)?
  • Tener el plugin de tomar la menor cantidad de recursos del servidor.
¿Fue útil?

Solución

Changing the word count on the home page is easy:

if( is_home() )
  add_filter( 'excerpt_length', create_function( '', 'return 300;' ) );

Just replicate that code and change the conditional check to add this to other pages. The other option is to just insert the code on the template page (home.php, tag.php, etc.), so you know it's going to be set on the correct page.

Using the_excerpt() will automatically strip shortcodes and html from the content if there's no excerpt provided. You can remove these filters, but it makes it much much harder to do word counts when you're adding markup into the mix. If you want the formatting/text/images preserved, that's what the more tag is for. It's inserted manually because it's too difficult to automatically figure out in all instances where that break should go.

Otros consejos

You can use the Fancy Excerpt Plugin For WordPress for that and modify it a bit. It preserves the style, does word-counting. You just need to modify this a bit to have your word-count and maybe if you don't like the ellipsis to modify the ending as well.

if you just need the first 300 words of the content you can easily get it with

wp_trim_words( $post->post_content, 300, '');
Licenciado bajo: CC-BY-SA con atribución
scroll top