立即注册 找回密码

QQ登录

只需一步,快速开始

查看: 4097|回复: 0

[Wordpress 通用教程] wordpress后台所有文章列表显示缩略图的具体方法

[复制链接]
发表于 2015-12-27 22:40:42 | 显示全部楼层 |阅读模式
道勤网-数据www.daoqin.net

亲注册登录道勤网-可以查看更多帖子内容哦!(包涵精彩图片、文字详情等)请您及时注册登录-www.daoqin.net

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 学习NO.1 于 2015-12-27 22:45 编辑

打开你主题的functions.php文件添加如下代码:

复制代码
  1. if ( !function_exists('fb_AddThumbColumn') && function_exists('add_theme_support') ) {
  2.    
  3.     // 在文章列表页与页面列表页添加缩略图列表
  4.     add_theme_support('post-thumbnails', array( 'post', 'page' ) );
  5.    
  6.     function fb_AddThumbColumn($cols) {
  7.         
  8.         $cols['thumbnail'] = __('Thumbnail');
  9.         
  10.         return $cols;
  11.     }
  12.    
  13.     function fb_AddThumbValue($column_name, $post_id) {
  14.             
  15.             $width = (int) 35;
  16.             $height = (int) 35;
  17.             
  18.             if ( 'thumbnail' == $column_name ) {
  19.                 // thumbnail of WP 2.9
  20.                 $thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true );
  21.                 // image from gallery
  22.                 $attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') ); www.111Cn.net
  23.                 if ($thumbnail_id)
  24.                     $thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
  25.                 elseif ($attachments) {
  26.                     foreach ( $attachments as $attachment_id => $attachment ) {
  27.                         $thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true );
  28.                     }
  29.                 }
  30.                     if ( isset($thumb) && $thumb ) {
  31.                         echo $thumb;
  32.                     } else {
  33.                         echo __('None');
  34.                     }
  35.             }
  36.     }
  37.    
  38.     // 文章页调用
  39.     add_filter( 'manage_posts_columns', 'fb_AddThumbColumn' );
  40.     add_action( 'manage_posts_custom_column', 'fb_AddThumbValue', 10, 2 );
  41.    
  42.     // 页面调用
  43.     add_filter( 'manage_pages_columns', 'fb_AddThumbColumn' );
  44.     add_action( 'manage_pages_custom_column', 'fb_AddThumbValue', 10, 2 );
  45. }
复制代码


如后台的效果

wordpress后台所有文章列表显示缩略图的具体方法

wordpress后台所有文章列表显示缩略图的具体方法

大家可以去测试下方法
道勤主机提供365天*24小时全年全天无休、实时在线、零等待的售后技术支持。竭力为您免费处理您在使用道勤主机过程中所遇到的一切问题! 如果您是道勤主机用户,那么您可以通过QQ【792472177】、售后QQ【59133755】、旺旺【诠释意念】、微信:q792472177免费电话、后台提交工单这些方式联系道勤主机客服! 如果您不是我们的客户也没问题,点击页面最右边的企业QQ在线咨询图标联系我们并购买后,我们为您免费进行无缝搬家服务,让您享受网站零访问延迟的迁移到道勤主机的服务!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

道勤网- 推荐内容!上一条 /2 下一条

!jz_fbzt! !jz_sgzt! !jz_xgzt! 快速回复 !jz_fhlb! !jz_lxwm! !jz_gfqqq!

关于我们|手机版|小黑屋|地图|【道勤网】-www.daoqin.net 软件视频自学教程|免费教程|自学电脑|3D教程|平面教程|影视动画教程|办公教程|机械设计教程|网站设计教程【道勤网】 ( 皖ICP备15000319号-1 )

GMT+8, 2024-5-4 17:58

Powered by DaoQin! X3.4 © 2016-2063 Dao Qin & 道勤科技

快速回复 返回顶部 返回列表