Posts list: show part of excerpt in Compact view if post has no title#11553
Posts list: show part of excerpt in Compact view if post has no title#11553sabernhardt wants to merge 2 commits intoWordPress:trunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| .trimmed-post-excerpt { | ||
| font-weight: 400; | ||
| padding-left: 4px; | ||
| } |
| * | ||
| * @param WP_Post $item The current WP_Post object. | ||
| */ | ||
| public function column_cb( $item ) { |
There was a problem hiding this comment.
The checkbox label should include the same text as the link (with 'Select').
The locked icon text might not require the same, but I updated that anyway.
| if ( 'excerpt' !== $mode && '' === get_the_title( $post ) && ! post_password_required( $post ) ) { | ||
| $excerpt = get_the_excerpt( $post ); | ||
| if ( '' !== $excerpt && is_string( $excerpt ) ) { | ||
| $title .= ' <span class="trimmed-post-excerpt">' . esc_html( wp_trim_words( $excerpt, 15, ' …' ) ) . '</span>'; |
There was a problem hiding this comment.
Escapes the output even though wp_trim_words() strips all tags, because it also has a wp_trim_words filter.
|
Tested via Playground and this works as expected for Posts and Pages, noting the excerpt/first bit of page content shows only on the Compact view and not on the Extended view. |
mcsf
left a comment
There was a problem hiding this comment.
Thanks for the patch, this is looking great. I've left some notes.
| if ( 'excerpt' !== $mode && '' === get_the_title( $post ) && ! post_password_required( $post ) ) { | ||
| $excerpt = get_the_excerpt( $post ); | ||
| if ( '' !== $excerpt && is_string( $excerpt ) ) { | ||
| $title .= ' <span class="trimmed-post-excerpt">' . esc_html( wp_trim_words( $excerpt, 15, ' …' ) ) . '</span>'; |
There was a problem hiding this comment.
About the $more string:
- Why the leading space? In my mind a simple
'…'makes the most sense, and this seems to be corroborated by the many priors in the codebase. - Do you think we should make it translateable? In my mind yes, but then I do see a lot of occurrences in Core — especially these older Admin pieces — of this ellipsis being hardcoded:
wp-includes/general-template.php :4783: $page_links[] = '<span class="page-numbers dots">' . __( '…' ) . '</span>';
wp-admin/edit-comments.php :169: $draft_or_post_title = wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '…' );
wp-admin/themes.php :252: <?php echo ! empty( $_GET['search'] ) ? __( '…' ) : count( $themes ); ?></span>
wp-admin/nav-menus.php :650: wp_html_excerpt( $_nav_menu->name, 40, '…' );
… whereas I expected something like:
// translators: If your locale needs a different [bla bla…]
$more = _x( '…', 'ellipsis or equivalent typographic marker of a trimmed excerpt' );
// ...
wp_trim_words( $excerpt, 15, $more ) )| <?php | ||
| /* translators: %s: Post title. */ | ||
| printf( __( 'Select %s' ), _draft_or_post_title() ); | ||
| printf( __( 'Select %s' ), $post_title ); |
There was a problem hiding this comment.
I wonder if this might make it more confusing for users with screen readers or not. Visual users have the luxury of styling to differentiate "(no title)" (bold) from the trimmed excerpt (regular weight).
Should we rearrange the output for screen readers? Otherwise it'll look like this:
<span class="screen-reader-text">Select (no title) Lorem ipsum dolor sit amet</span>

If the post/page has no title and the excerpt is not already showing, this
Trac 65022
Use of AI Tools: none
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.