Skip to content

Commit

Permalink
Merge pull request #111 from billerickson/fix-excerpts
Browse files Browse the repository at this point in the history
Fix excerpts, fixes #110
  • Loading branch information
billerickson committed Jun 5, 2016
2 parents cf2105c + adafa11 commit 3dfa5a1
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions display-posts-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function be_display_posts_shortcode( $atts ) {
'display_posts_off' => false,
'excerpt_length' => false,
'excerpt_more' => false,
'excerpt_more_link' => false,
'exclude_current' => false,
'id' => false,
'ignore_sticky_posts' => false,
Expand Down Expand Up @@ -118,6 +119,7 @@ function be_display_posts_shortcode( $atts ) {
$date_query_compare = sanitize_text_field( $atts['date_query_compare'] );
$excerpt_length = intval( $atts['excerpt_length'] );
$excerpt_more = sanitize_text_field( $atts['excerpt_more'] );
$excerpt_more_link = filter_var( $atts['excerpt_more_link'], FILTER_VALIDATE_BOOLEAN );
$exclude_current = filter_var( $atts['exclude_current'], FILTER_VALIDATE_BOOLEAN );
$id = $atts['id']; // Sanitized later as an array of integers
$ignore_sticky_posts = filter_var( $atts['ignore_sticky_posts'], FILTER_VALIDATE_BOOLEAN );
Expand Down Expand Up @@ -419,9 +421,24 @@ function be_display_posts_shortcode( $atts ) {
$author = apply_filters( 'display_posts_shortcode_author', ' <span class="author">by ' . get_the_author() . '</span>' );

if ( $include_excerpt ) {
$excerpt_length = $excerpt_length ? $excerpt_length : apply_filters( 'excerpt_length', 55 );
$excerpt_more = $excerpt_more ? $excerpt_more : apply_filters( 'excerpt_more', ' ' . '[&hellip;]' );
$excerpt = ' <span class="excerpt-dash">-</span> <span class="excerpt">' . wp_trim_words( get_the_excerpt(), $excerpt_length, $excerpt_more ) . '</span>';

// Custom build excerpt based on shortcode parameters
if( $excerpt_length || $excerpt_more || $excerpt_more_link ) {

$length = $excerpt_length ? $excerpt_length : apply_filters( 'excerpt_length', 55 );
$more = $excerpt_more ? $excerpt_more : apply_filters( 'excerpt_more', '' );
$more = $excerpt_more_link ? ' <a href="' . get_permalink() . '">' . $more . '</a>' : ' ' . $more;

$excerpt = has_excerpt() ? $post->post_excerpt . $more : wp_trim_words( $post->post_content, $length, $more );

// Use default, can customize with WP filters
} else {
$excerpt = get_the_excerpt();
}

$excerpt = ' <span class="excerpt-dash">-</span> <span class="excerpt">' . $excerpt . '</span>';


}

if( $include_content ) {
Expand Down Expand Up @@ -653,4 +670,4 @@ function be_display_posts_off( $out, $pairs, $atts ) {
*/
$out['display_posts_off'] = apply_filters( 'display_posts_shortcode_inception_override', true );
return $out;
}
}

0 comments on commit 3dfa5a1

Please sign in to comment.