I'm using this in my functions file...
function twentyten_custom_excerpt_more( $output ) {
if ( has_excerpt() && ! is_attachment() ) {
$output .= twentyten_continue_reading_link();
}
return $output;
}
add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );
/* Custome Excerpt Lengths */
function cust_excerpt($charlength) {
$excerpt = get_the_excerpt();
$charlength++;
if(strlen($excerpt)>$charlength) {
$subex = substr($excerpt,0,$charlength-5);
$exwords = explode(" ",$subex);
$excut = -(strlen($exwords[count($exwords)-1]));
if($excut<0) {
echo substr($subex,0,$excut);
} else {
echo $subex;
}
echo "...";
} else {
echo $excerpt;
}
}
and calling it in the loop like so...
<?php echo cust_excerpt(120); ?>
The issue i am having is with the following code...
<!-- Get posts -->
<?php get_featured_posts(array('method' => 'the_loop')); while (have_posts()) : the_post(); ?>
<!-- get thumbnail -->
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<?php if ( has_post_thumbnail() ) the_post_thumbnail('header-large-thumb'); else { ?>
<img src="<?php bloginfo( 'template_directory' ); ?>/images/placeholder-image.jpg" width="490px" height="277px" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /><?php } ?>
</a>
<!-- get post title -->
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
<!-- get post meta -->
<?php the_time('F jS, Y') ?> • by <?php the_author_posts_link(); ?>
<!-- Get social plugin -->
<?php
if(function_exists('display_social4i'))
echo display_social4i("large","float-left");
?>
<!-- Get custom excerpt -->
<?php echo cust_excerpt(300); ?>
<!-- kill loop -->
<?php endwhile; wp_reset_query(); ?>
The issue is that when i try and have an excerpt length of 300 it just won't happen, it stays at around 120 and also the ellipses go from what they should be ... to the default WP ones of [...] this makes me think it's defaulting to the original excerpts somehow.
Any thoughts? Or anyone know of a better way of getting custom excerpt lengths?
This post has been edited by MikeChipshop: 24 January 2012 - 12:25 PM
Help




















