I am customizing a widget used for displaying testimonials. The widget is working fine, except it shows all content and i want to limit the text/characters so the footer of the website looks balance. Here is the widget code snippet:
function widget( $args, $instance ) {
extract( $args );
$title = $instance['title'] ;
$count = $instance['count'];
$url = $instance['url'];
echo $before_widget;
echo '<div class="testimonials-container">';
if ( $title )
echo '<h3 class="replace"><a href="' . $url . '">' . $title . '</a></h3>' ;
?>
<?php
$query = new WP_Query();
$query->query('post_type=testimonial&posts_per_page='.$count);
?>
<?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
<div class="testimonials-content">
<?php limit_text(the_content(), 15); ?>
<span class="testimonial-name"><em>
<?php echo get_post_meta(get_the_ID(), 'pkb_author_name', true); ?></em></span>
</div>
<?php endwhile; endif;?>
To truncate it, i use this:
function limit_text($text, $limit) {
if (strlen($text) > $limit) {
$words = str_word_count($text, 2);
$pos = array_keys($words);
$text = substr($text, 0, $pos[$limit]) . '...';
}
return $text;
}
Its not working. What am i doing wrong here?