Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update display-posts-shortcode.php #251

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions display-posts-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Display Posts
* Plugin URI: https://displayposts.com
* Description: Display a listing of posts using the [display-posts] shortcode
* Version: 3.1.1
* Version: 3.1.2
* Author: Bill Erickson
* Author URI: https://www.billerickson.net
* Text Domain: display-posts
Expand All @@ -16,7 +16,7 @@
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @package Display Posts
* @version 3.1.1
* @version 3.1.2
* @author Bill Erickson <[email protected]>
* @copyright Copyright (c) 2011, Bill Erickson
* @link https://displayposts.com
Expand Down Expand Up @@ -87,6 +87,7 @@ function be_display_posts_shortcode( $atts ) {
'include_excerpt' => false,
'include_excerpt_dash' => true,
'include_link' => true,
'include_unpublished_links' => false,
'include_title' => true,
'meta_key' => '', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_key
'meta_value' => '', // phpcs:ignore WordPress.VIP.SlowDBQuery.slow_db_query_meta_value
Expand Down Expand Up @@ -153,6 +154,7 @@ function be_display_posts_shortcode( $atts ) {
$include_excerpt = filter_var( $atts['include_excerpt'], FILTER_VALIDATE_BOOLEAN );
$include_excerpt_dash = filter_var( $atts['include_excerpt_dash'], FILTER_VALIDATE_BOOLEAN );
$include_link = filter_var( $atts['include_link'], FILTER_VALIDATE_BOOLEAN );
$include_unpublished_links = filter_var( $atts['include_unpublished_links'], FILTER_VALIDATE_BOOLEAN );
$meta_key = sanitize_text_field( $atts['meta_key'] );
$meta_value = sanitize_text_field( $atts['meta_value'] );
$no_posts_message = sanitize_text_field( $atts['no_posts_message'] );
Expand Down Expand Up @@ -492,24 +494,28 @@ function be_display_posts_shortcode( $atts ) {
$author = '';
$excerpt = '';
$content = '';
$status = get_post_status($post->ID);

if ( $include_title && $include_link ) {
/** This filter is documented in wp-includes/link-template.php */
$title = '<a class="title" href="' . apply_filters( 'the_permalink', get_permalink() ) . '">' . get_the_title() . '</a>';
$title = '';
if ( $include_title ) {
$title = get_the_title();

} elseif ( $include_title ) {
$title = '<span class="title">' . get_the_title() . '</span>';

} else {
$title = '';
if ( ( $status == 'publish' && $include_link ) || $include_unpublished_links ) {
/** This filter is documented in wp-includes/link-template.php */
$title = '<a class="title ' . $status . '" href="' . apply_filters( 'the_permalink', get_permalink() ) . '">' . $title . '</a>';
} else {
$title = '<span class="title ' . $status . '">' . $title . '</span>';
}
}

if ( $image_size && has_post_thumbnail() && $include_link ) {
$image = '<a class="image" href="' . get_permalink() . '">' . get_the_post_thumbnail( get_the_ID(), $image_size ) . '</a> ';

} elseif ( $image_size && has_post_thumbnail() ) {
$image = '<span class="image">' . get_the_post_thumbnail( get_the_ID(), $image_size ) . '</span> ';

if ( $image_size && has_post_thumbnail() ) {
$image = get_the_post_thumbnail( get_the_ID(), $image_size );

if ( ( $status == 'publish' && $include_link ) || $include_unpublished_links ) {
$image = '<a class="image ' . $status . '" href="' . get_permalink() . '">' . $image . '</a> ';
} else {
$image = '<span class="image ' . $status . '">' . $image . '</span> ';
}
}

if ( $include_date ) {
Expand Down Expand Up @@ -541,7 +547,8 @@ function be_display_posts_shortcode( $atts ) {

$length = $excerpt_length ? $excerpt_length : apply_filters( 'excerpt_length', 55 );
$more = $excerpt_more ? $excerpt_more : apply_filters( 'excerpt_more', '' );
$more = $excerpt_more_link ? ' <a class="excerpt-more" href="' . get_permalink() . '">' . $more . '</a>' : ' <span class="excerpt-more">' . $more . '</span>';
$more = $excerpt_more_link && ( $status == 'publish' || $include_unpublished_links ) ? ' <a class="excerpt-more" href="' . get_permalink() . '">' . $more . '</a>' : ' <span class="excerpt-more">' . $more . '</span>';


if ( has_excerpt() && apply_filters( 'display_posts_shortcode_full_manual_excerpt', false ) ) {
$excerpt = $post->post_excerpt . $more;
Expand Down