mdavison/Excerpt ( PHP)
function excerpt($string='', $maxChar=50, $uri='#') {
$length = strlen($string);
if ($length < $maxChar) {
return $string;
}
$trimmedString = substr($string, 0, $maxChar);
$wordsArray = str_word_count($trimmedString, 1);
array_pop($wordsArray);
$newString = implode(' ', $wordsArray) . ' <a href="' . $uri . '">more</a>';
return $newString;
}
Creates excerpt that breaks at end of word.
cessnajumpin/Excerpt with Tag Stripping ( PHP)
public function makeNewsExcerpt($content)
{
$content = preg_replace("(\<(/?[^\>]+)\>)", "", $content);
$content = substr($content, 0, 160);
$content .= "...";
return $content;
}
Create an excerpt from the main copy, removing any image or other HTML tag markup so it will be clean. In this case the length is 160 characters, change that number to change the length of the excerpt
hussong/Add excerpts to pages ( PHP)
// add excerpt to pages add_post_type_support( 'page', 'excerpt' );
Adds support for excerpts in WordPress pages. Great for using WordPress as a CMS. A text field appears in the admin panel and you can pull the excerpt from your template files (for teaser texts etc.)
prwhitehead/Create Wordpress Text Excerpts with PHP ( PHP)
/**
* usage:
* $txt = new($post->post_content, 50, 'Read in full', '<span class="readmore">', '</span>', '<a><span>');
* echo $text->createExcerpt();
*
*/
class text{
public $text;
public $length;
public $allowedTags;
public $readMoreText;
//create internal variables from those passed to the class
function __construct($text = '',
$length = 50,
$readMoreText = 'Read In Full...',
$before = '',
$after = '',
$allowedTags = '<a>') {
$this->text = $text;
$this->length = $length;
$this->readMoreText = $readMoreText;
$this->before = $before;
$this->after = $after;
$this->allowedTags = $allowedTags;
}
//shorten text to required length
public function shortenText() {
//explode the string into an array of the length we want
if (count(explode(' ', $this->text)) > $this->length)
{
$textArray = explode(' ', $this->text, $this->length);
//remove the excess string from the end of the array
array_pop($textArray);
//create a string from the array
$textString = implode(' ', $textArray);
//cleaning up
unset($textArray);
//return
return $textString . '... ';
}
else
{
return $this->text;
}
}
//remove tags and other.
public function cleanText($text){
//strip the text of html tags, except those we want
$strippedText = strip_tags($text, $this->allowedTags);
//remove [] and their content
$strippedText = preg_replace('`\[[^\]]*\]`','',$strippedText);
//return
return $strippedText;
}
//create output
public function createExcerpt(){
global $post;
//create output
$output = '';
$output .= $this->cleanText($this->shortenText());
if($this->readMoreText !== '')
{
$output .= $this->before;
$output .= ' <a href="'. $post->guid .'" title="'. $this->readMoreText . ': '. $post->post_title .'">'. $this->readMoreText . '</a>';
$output .= $this->after;
}
return $output;
}
}//end class//
Create excerpts from text block from your wordpress content and add links page / post from the guid.
paulund/Change Excerpt Length in Wordpress ( PHP)
function new_excerpt_length($length) {
return 100;
}
add_filter('excerpt_length', 'new_excerpt_length');
Xtraboy/Replace Excerpt Ellipsis with Permalink ( PHP)
function replace_excerpt($content) {
return str_replace('[...]',
'<div class="more-link"><a href="'. get_permalink() .'">Continue Reading</a></div>',
$content
);
}
add_filter('the_excerpt', 'replace_excerpt');
svenkaemper/Excerpts in WordPress ( PHP)
<?php
//display all post titles, and if an excerpt exists, show it
$posts=get_posts('post_type=post&showposts=-1');
if ($posts) {
foreach($posts as $post) {
setup_postdata($post);
?>
<p><?php the_time('m.d.y') ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
if ($post->post_excerpt) {
echo 'excerpt is:' . $post->post_excerpt;
}
}
}
?>
Joergermeister/Wordpress Excerpt Loop ( PHP)
<?php if ( is_home() || is_archive()|| is_search() ) : ?>
serialk89/EXCERPT PERSONALIZADO LA CANTIDAD DE CARACTERES ( PHP)
global $post;
$args = array('numberposts' => 3, 'offset'=> 0, 'order'=> 'DESC' );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post);
$excerpt = get_the_excerpt();
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 145, 100, true ); // Normal post thumbnails
add_image_size( 'single-post-thumbnail', 400, 9999 ); // Permalink thumbnail size
?>
<div class="homepostd">
<div class="thumbd">
<a title="<?php the_title(); ?>" rel="bookmark" href="<?php the_permalink(); ?>">
<?php
if(has_post_thumbnail()) {
the_post_thumbnail(array(145,100));
} else {
echo '<img src="'.get_bloginfo("template_url").'/images/img-default.jpg" width="150" height="64" />';
}
?>
</a>
</div>
<div class="rightcontpd">
<b><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></b>
<?php echo string_limit_words($excerpt,10);?><a href="<?php the_permalink(); ?>">[...]</a>
</div>
</div>
<?php endforeach; ?>
Por parámetro selecciono la cantidad de caracteres que quiero que me muestre the_excerpt() en wordpress
kristarella/Limit WordPress excerpts ( PHP)
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'custom_trim_excerpt');
function custom_trim_excerpt($text) { // Fakes an excerpt if needed
global $post;
if ( '' == $text ) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$excerpt_length = x;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
array_push($words, '...');
$text = implode(' ', $words);
}
}
return $text;
}
Thanks to LenK on the WP forums.
mzym/Output WordPress Excerpts ( PHP)
function outputExcerpts() {
$result_list = mysql_query("SELECT * FROM wp_posts WHERE post_type='post' AND post_status='publish' ORDER BY post_date DESC");
if ($myrow_list = mysql_fetch_array($result_list)) {
do {
$listExcerpts[] = $myrow_list;
} while ($myrow_list = mysql_fetch_array($result_list));
}
return $listExcerpts;
}
Create an own query to WordPress for your own templates (i.e. Smarty)
kai330/Wordpress excerpt custom word limitation ( PHP)
<?php
//this part goes to functions.php
function string_limit_words($string, $word_limit)
{
$words = explode(' ', $string, ($word_limit + 1));
if(count($words) > $word_limit) {
array_pop($words);
//add a ... at last article when more than limit word count
echo implode(' ', $words)."..."; } else {
//otherwise
echo implode(' ', $words); }
}
//this part goes to template
$excerpt = get_the_excerpt();
echo string_limit_words($excerpt,25);
?>
Xtraboy/Improving WordPress’ the_excerpt() template tag ( PHP)
function improved_trim_excerpt($text) {
global $post;
if ( '' == $text ) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]&gt;', $text);
$text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
$text = strip_tags($text, '<p>');
$excerpt_length = 80;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words)> $excerpt_length) {
array_pop($words);
array_push($words, '[...]');
$text = implode(' ', $words);
}
}
return $text;
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'improved_trim_excerpt');
Joergermeister/WordPress “the_excerpt” nur auf bestimmten Seiten oder Archiven ( PHP)
<?php if ( is_home() || is_category(array('Kategorie1','Kategorie3','Kategorie5')) || is_author() || is_date() || is_tag() || is_search() ) : // Excerpts nur auf bestimmten Seiten. ?>
johnsardine/Wordpress - Custom Except Anywhere ( PHP)
//Excerpt - usage - < ?php echo excerpt(15); ? > - remove the spaces between the < and ?
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}
I did not created this, a friend provided it to me, and it seems really usefull so i thought i should share.
Usage: Paste that code in your functions .php and in your theme you put <?php> where 20 is the number of words you want