Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/wp-admin/css/list-tables.css
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ td.plugin-title p {
margin: 6px 0;
}

.trimmed-post-excerpt {
font-weight: 400;
padding-left: 4px;
}
Comment on lines +366 to +369
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I want the lighter font-weight when it is still part of the link, but I like having a small amount of padding to offset the excerpt.

Posts list with published and draft posts, in Compact view, with excerpts for titleless posts

And the title is not linked in Trash:

post without a title, showing trimmed excerpt in Trash


/* Media file column */
table.media .column-title .media-icon {
float: left;
Expand Down
26 changes: 24 additions & 2 deletions src/wp-admin/includes/class-wp-posts-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1018,9 +1018,13 @@ private function _page_rows( &$children_pages, &$count, $parent_page, $level, $p
* @since 4.3.0
* @since 5.9.0 Renamed `$post` to `$item` to match parent class for PHP 8 named parameter support.
*
* @global string $mode List table view mode.
*
* @param WP_Post $item The current WP_Post object.
*/
public function column_cb( $item ) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

global $mode;

// Restores the more descriptive, specific name for use within this method.
$post = $item;

Expand All @@ -1037,13 +1041,23 @@ public function column_cb( $item ) {
* @param WP_Post $post The current WP_Post object.
*/
if ( apply_filters( 'wp_list_table_show_post_checkbox', $show, $post ) ) :

$post_title = _draft_or_post_title();

// If the post has no title, try adding part of the excerpt.
if ( 'excerpt' !== $mode && '' === get_the_title( $post ) && ! post_password_required( $post ) ) {
$excerpt = get_the_excerpt( $post );
if ( '' !== $excerpt && is_string( $excerpt ) ) {
$post_title .= ' ' . esc_html( wp_trim_words( $excerpt, 15, ' …' ) );
}
}
?>
<input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" />
<label for="cb-select-<?php the_ID(); ?>">
<span class="screen-reader-text">
<?php
/* translators: %s: Post title. */
printf( __( 'Select %s' ), _draft_or_post_title() );
printf( __( 'Select %s' ), $post_title );
?>
</span>
</label>
Expand All @@ -1054,7 +1068,7 @@ public function column_cb( $item ) {
printf(
/* translators: Hidden accessibility text. %s: Post title. */
__( '&#8220;%s&#8221; is locked' ),
_draft_or_post_title()
$post_title
);
?>
</span>
Expand Down Expand Up @@ -1142,6 +1156,14 @@ public function column_title( $post ) {

$title = _draft_or_post_title();

// If the post has no title, try adding part of the excerpt.
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, ' &hellip;' ) ) . '</span>';
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Escapes the output even though wp_trim_words() strips all tags, because it also has a wp_trim_words filter.

}
}

if ( $can_edit_post && 'trash' !== $post->post_status ) {
printf(
'<a class="row-title" href="%s">%s%s</a>',
Expand Down
Loading