I'm using the following code to grab a string and return a spesific number of characters
<div class="top_posts">
<ul>';
}
elseif($i>1 && $i<=$number_of_posts)
{
$retour.= "\n" . '<li>';
if($image_url) { $retour .= '<a href="' . get_permalink() . '"><img src="' . get_bloginfo('tem开发者_JAVA百科plate_directory') . '/js/timthumb.php?src=' . $image_url . '&h=120&w=180&zc=1" alt="" /></a>'; }
$retour .= '<h6><a href="' . get_permalink() . '">' . the_title("","",false) . '</a></h6>';
$retour.= get_wpe_excerpt('wpe_popular_posts');
$retour.='</li>';
if($i%2==1)
$retour.= "\n" . '<li class="clear">&</li>';
}
$i++;
endforeach;
$retour.='</ul></div>';
return $retour;
}
add_shortcode('popular-posts', 'popular_posts_code');
The chunk at issue is this part
$retour.= get_wpe_excerpt('wpe_popular_posts');
which calls to
function wpe_popular_posts($length) {
return 55;
}
However I'm still getting the full text string untrimmed - any help appreciated.
//update
The get_wpe_excerpt function looks like this
function get_wpe_excerpt($length_callback='', $more_callback='') {
if(function_exists($length_callback)){
add_filter('excerpt_length', $length_callback);
}
if(function_exists($more_callback)){
add_filter('excerpt_more', $more_callback);
}
$output = get_the_excerpt();
$output = apply_filters('wptexturize', $output);
$output = apply_filters('convert_chars', $output);
$output = '<p>'.$output.'</p>';
return $output;
}
Now sure how the get_wpe_excerpt() function is done. You may want to try the simple code I used in several WordPress themes.
implode(' ', array_slice(explode(' ', get_the_content()), 0, 55));
You want to return the first 55 characters of the string?
Try substr($input, 0, 55);
However I really don't understand what's going on with that call to $retour.= get_wpe_excerpt('wpe_popular_posts');
... so maybe I am misunderstanding what you are trying to achieve?
精彩评论