Skip to content

Commit

Permalink
Use untitled as fallback title when missing in listing latest-posts
Browse files Browse the repository at this point in the history
Fixes #1990
  • Loading branch information
westonruter committed Jul 25, 2017
1 parent 11522a0 commit 813af21
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion blocks/library/latest-posts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ registerBlockType( 'core/latest-posts', {
>
{ latestPosts.map( ( post, i ) =>
<li key={ i }>
<a href={ post.link } target="_blank">{ post.title.rendered }</a>
<a href={ post.link } target="_blank">{ post.title.rendered.trim() || __( '(Untitled)' ) }</a>
{ displayPostDate && post.date_gmt &&
<time dateTime={ moment( post.date_gmt ).utc().format() } className={ `${ this.props.className }__post-date` }>
{ moment( post.date_gmt ).local().format( 'MMM DD h:mm A' ) }
Expand Down
6 changes: 5 additions & 1 deletion lib/blocks/latest-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ function gutenberg_render_block_core_latest_posts( $attributes ) {
foreach ( $recent_posts as $post ) {
$post_id = $post['ID'];

$title = get_the_title( $post_id );
if ( ! $title ) {
$title = __( '(Untitled)', 'gutenberg' );
}
$posts_content .= sprintf(
'<li><a href="%1$s">%2$s</a>',
esc_url( get_permalink( $post_id ) ),
esc_html( get_the_title( $post_id ) )
esc_html( $title )
);

if ( $attributes['displayPostDate'] ) {
Expand Down

0 comments on commit 813af21

Please sign in to comment.