Das PHP Script Verzeichnis

Mit der folgenden Funktion kann man den Text auf der Startseite des WordPress Blogs automatisch begrenzen. Dazu wird die Funktion in die functions.php Datei des aktuell genutzen Themes eingestet. In der Variabel „$excerpt_length = 55;“ gibt die Zahl der Anzahl an Worten, die gezeigt werden sollen an. Im Beispiel sind es 55 Worte.

function my_excerpts($content = false) {
// If is the home page, an archive, or search results
if(is_front_page() || is_archive() || is_search()) :
global $post;
$content = $post->post_excerpt;
 

// If an excerpt is set in the Optional Excerpt box
if($content) :
$content = apply_filters('the_excerpt', $content);

// If no excerpt is set
else :
$content = $post->post_content;
$excerpt_length = 55;
$words = explode(' ', $content, $excerpt_length + 1);
if(count($words) > $excerpt_length) :
array_pop($words);
array_push($words, '...');
$content = implode(' ', $words);
endif;
$content = '<p>' . $content . '</p>';

endif;
endif;

// Make sure to return the content
return $content;

}

add_filter('the_content', 'my_excerpts');
[/php]
Dieser nützliche Hack stammt von Justin Tadlock