本帖最后由 wpocn 于 2023-2-28 14:07 编辑
WordPress 自带的特色图片功能用于生成缩略图,但默认情况下,WordPress并没有为我们提供查看某篇文章是滞添加了特色图片功能,可以通过下面的代码,在后台文章列表中显示文章的特色图片。
将代码添加到当前主题函数模板 functions.php 中:
- // 在后台文章列表添加特色图片列
- add_filter( 'manage_post_posts_columns', 'featured_image' );
- function featured_image( $columns ) {
- $columns['featured_image_col'] = '特色图片';
- return $columns;
- }
-
- // 有特色图片则显示,否则显示占位图
- add_action( 'manage_post_posts_custom_column','featured_image_col_callback', 10,2 );
- function featured_image_col_callback( $column, $pid ) {
- Switch( $column ) {
- case 'featured_image_col':
- if ( get_post_thumbnail_id( $pid ) )
- echo get_the_post_thumbnail( $pid, array( 80, 60 ) );
- else
- echo '<img src="data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs=" class="wp-post-image" decoding="async" loading="lazy" width="80" height="60">';
- break;
- }
- }
复制代码 本文来自:https://www.wpocn.com/
|