Jump to content

How to Limit Synopsis the_content Words


Babaman

Publicaciones recomendadas

You use the_content function in almost every page of your dooplay theme. For instance you use in peliculas.php, series.php file and  it will echo all the content for one post or page. But you don’t want to show all content. Maybe only 80 words. Here how you can limit the_content

Using Custom Function

This method is going to be the best and most flexible way to limit the_content words length. Write the following custom function in your functions.php file.

function dooplay_content($limit){
  $content = explode(' ', get_the_content(), $limit);

  if (count($content)>=$limit){
       array_pop($content);
       $content = implode(" ",$content).'...';
  } else {
    $content = implode(" ",$content);
  }
	
  $content = preg_replace('/\[.+\]/','', $content);
  $content = apply_filters('the_content', $content); 
  $content = str_replace(']]>', ']]>', $content);
  return $content;
}

Use the custom function instead of the_content. For example:

<?php echo dooplay_content(80); ?>

 

Editado por Babaman
Enlace al comentario
Compartir en otros sitios web

  • Usuarios conectados   0 Miembros, 0 Anónimos, 2 Invitados (Ver lista completa)

    • Actualmente no hay usuarios registrados en línea
×
×
  • Crear nuevo...