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

[ Latest Posts ] Fixes the read more link added by themes in Latest Posts #20541

Merged
merged 2 commits into from
Mar 30, 2020
Merged
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
17 changes: 3 additions & 14 deletions packages/block-library/src/latest-posts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function block_core_latest_posts_get_excerpt_length() {
* @return string Returns the post content with latest posts added.
*/
function render_block_core_latest_posts( $attributes ) {
global $block_core_latest_posts_excerpt_length;
global $post, $block_core_latest_posts_excerpt_length;

$args = array(
'posts_per_page' => $attributes['postsToShow'],
Expand All @@ -55,6 +55,7 @@ function render_block_core_latest_posts( $attributes ) {
$list_items_markup = '';

foreach ( $recent_posts as $post ) {

$list_items_markup .= '<li>';

if ( $attributes['displayFeaturedImage'] && has_post_thumbnail( $post ) ) {
Expand Down Expand Up @@ -108,21 +109,9 @@ function render_block_core_latest_posts( $attributes ) {
$trimmed_excerpt = get_the_excerpt( $post );

$list_items_markup .= sprintf(
'<div class="wp-block-latest-posts__post-excerpt">%1$s',
'<div class="wp-block-latest-posts__post-excerpt">%1$s</div>',
$trimmed_excerpt
);

if ( strpos( $trimmed_excerpt, ' &hellip; ' ) !== false ) {
$list_items_markup .= sprintf(
'<a href="%1$s">%2$s</a></div>',
esc_url( get_permalink( $post ) ),
__( 'Read more' )
);
} else {
$list_items_markup .= sprintf(
'</div>'
);
}
}

if ( isset( $attributes['displayPostContent'] ) && $attributes['displayPostContent']
Expand Down