Homepage › Community Forums › Epik Theme Support › Portfolio: custom excerpt length
Tagged: portfolio
For portfolio page items, I can either
A) choose how much I want displayed per portfolio item: use “display post content” and insert [Read more] in the post content to break it
OR
B) choose how much I want displayed for all portfolio items (unflexible): use “display post excerpt”
I’d like to keep control of how much gets displayed per portfolio item. Problem is the content in the post (portfolio item) has a left aligned image at the beginning, and this image shows up in the summary, which looks very bad.
How do I get the best of both worlds. There are a couple ways to do it, but I’m thinking about filtering out img tags from the post content above [Read more]. How do I accomplish this?
Thanks
I’m not sure if it’s possible with this portfolio (out of the box). I remember attempting this before and couldn’t get it to work. You would probably need to make some customizations to get something like that to work where each post is based on the read more/excerpt. This has to do with the portfolio template, the loop and the Genesis Framework.
Anyone else have any experience on how to do something like this with excerpts?
Thanks Kronos.
@eddieb I don’t know if you’ve solved this or not, but below is a standard code snippet I use on most sites I create to improve the out-of-the-box “excerpt” function in WordPress……this would let you use the Portfolio setting to display excerpts and have greater control over what appears in the excerpt. You can add formatting tags to what does NOT stripped where you see $text = strip_tags and you can modify the number of word where you see $excerpt_length (note: this is words, not characters). Maybe this will help?
// Improves the look of the excerpt, more words, allows bolding
function improved_trim_excerpt($text) {
$raw_excerpt = $text;
if ( '' == $text ) {
$text = get_the_content('');
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace('\]\]\>', ']]>', $text);
$text = strip_tags($text, '<b><strong>');
$excerpt_length = apply_filters('excerpt_length', 55);
$newexcerpt_more = apply_filters('excerpt_more', 'new_excerpt_more');
$words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
if ( count($words) > $excerpt_length ) {
array_pop($words);
$text = implode(' ', $words);
$text = $text . $newexcerpt_more;
$text = force_balance_tags( $text );
} else {
$text = implode(' ', $words);
$text = force_balance_tags( $text );
}
}
return $text;
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'improved_trim_excerpt');
<!--formatted-->
