1

I want to make in my style for WP excerpt like

HERE

When post title is higher, excerpt is reduced to smaller. Its a plugin or something else?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Damian
  • 602
  • 7
  • 18
  • You can count title length and adopt this: http://stackoverflow.com/questions/4082662/multiple-excerpt-lengths-in-wordpress – Michal S Mar 09 '14 at 14:56
  • This is for word limit, i need excerpt height limit. For example max height of excerpt is 100px but excerpt need 150px. On the end of the line at 100px after last word add "..." – Damian Mar 09 '14 at 15:06
  • height will be in browser, on server site you can just estimate based on... characters count. – Michal S Mar 09 '14 at 15:08
  • sure we can write in polish, but it against policy here. You can contact using contacts from my web site. – Michal S Mar 09 '14 at 15:12
  • Ok sory, im newbie here... – Damian Mar 09 '14 at 15:12
  • You have message from me on Facebook. Check your "others" messages. – Damian Mar 09 '14 at 15:27
  • for using JQuery on browser side see this: http://blog.johnavis.com/blog/default.asp?id=589 – Michal S Mar 09 '14 at 15:32

2 Answers2

1

I just found a solution to limiting the number of words in the excerpt without plugins. Add the following code to your functions.php file.

<?php
// Custom Excerpt 
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;
}

// Content Limit 
function content($limit) {
$content = explode(' ', get_the_content(), $limit);
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content).'...';
} else {
$content = implode(" ",$content);
} 
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content); 
$content = str_replace(']]>', ']]&gt;', $content);
return $content;
}
?>

If you want to limit your excerpt to 25 words the code would look like this:

<?php echo excerpt(25); ?>
<?php echo content(25); ?>

Another way to display limited excerpt by character. Here is the functions.php file code.

<?php
function get_excerpt(){
$excerpt = get_the_content();
$excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, 100);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
$excerpt = $excerpt.'... <a href="'.get_the_permalink().'">Read More</a>';
return $excerpt;
}
?>

After this you need to add where you want to display your customized character by character.

<?php echo get_excerpt(); ?>

Source: Web Design Company Bangladesh

csehasib
  • 365
  • 3
  • 7
0

Do it with CSS:

.truncated_exercept{
overflow:hidden;
text-overflow:ellipsis;
}

but in more then one line in current CSS is not possible with nice … (...) ending, have to use one of js or js+jQuery solutions look there:
http://dotdotdot.frebsite.nl/

Michal S
  • 1,104
  • 17
  • 26