corey
asked 10 years ago

Hello,

My client wants to be able to change the length for the DW Categories widget. They want the current excerpt length for the rest of wordpress to remain the same but only change the length of the excerpts for the DW Categories widget.
Thanks!

1 Answers
Wilfred
answered 10 years ago

Hi corey,
To resolve this issue please follow my instruction here:
1. Open functions.php file in /wp-content/themes/dw-focus/functions.php
2. Add following code 

function the_content_max_charlength($charlength) {
$content = get_the_content();
$charlength++;
if ( mb_strlen( $content ) > $charlength ) {
$subex = mb_substr( $content, 0, $charlength - 5 );
$exwords = explode( ' ', $subex );
$excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
if ( $excut < 0 ) {
echo mb_substr( $subex, 0, $excut );
} else {
echo $subex;
}
} else {
echo $content;
}
}

3.Open dw-focus-categories.php file in /wp-content/themes/dw-focus/inc/widgets/dw-focus-categories.php 4. Replace following code – line 293 & 407 

<?php the_excerpt();  ?>

with:

<?php the_content_max_charlength(140); ?>

Hope this helps!

Deborah Buck
replied 10 years ago

I followed these instructions, and it didn’t work. Not only did the excerpt length remain unaffected, the right-bar widgets disappeared. Is there a specific spot in the code that the function should be dropped into? I just put it at the end.

Deborah Buck
replied 10 years ago

I did some further testing. The function didn’t break anything. The replacing of the first instance of the_excerpt() didn’t break anything. However, replacing the second instance of the_excerpt() did break the site as described above.

Also, why does the function use get_the_content() and not the_excerpt()?

Deborah Buck
replied 10 years ago

Ah ha! Sorry for the multiple posts here, but I couldn’t let this bone go. I finally found the root of my problem. The mb_strlen function isn’t supported with my server’s install of PHP. http://technaugh.com/technaugh/dotproject/call-to-undefined-function-mb_strpos-or-mb_stripos-or-mb_strlen-or-mb_strtoupper-or-mb_stristrll/
Since it’s a shared server environment, I cannot change this. I rewrote the function above to utilize the “normal” strlen() and substr() functions.
The site is no longer broken, and my excerpts are getting trimmed nicely.

Powered by DW Question & Answer Pro