为WordPress 后台文章列表添加缩略图

wordpress 2.9版引入文章缩略图的功能,这个特色图像功能,不仅可以在前台显示,后台文章列表中也可以显示缩略图。

将如下代码添加到当前主题functions.php中:
- if ( !function_exists(‘fb_AddThumbColumn’) && function_exists(‘add_theme_support’) ) {
 - // for post and page
 - add_theme_support(‘post-thumbnails’, array( ‘post’, ‘page’ ) );
 - function fb_AddThumbColumn($cols) {
 - $cols[‘thumbnail’] = __(‘Thumbnail’);
 - return $cols;
 - }
 - function fb_AddThumbValue($column_name, $post_id) {
 - $width = (int) 35;
 - $height = (int) 35;
 - if ( ‘thumbnail’ == $column_name ) {
 - // thumbnail of WP 2.9
 - $thumbnail_id = get_post_meta( $post_id, ‘_thumbnail_id’, true );
 - // image from gallery
 - $attachments = get_children( array(‘post_parent’ => $post_id, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’) );
 - if ($thumbnail_id)
 - $thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
 - elseif ($attachments) {
 - foreach ( $attachments as $attachment_id => $attachment ) {
 - $thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true );
 - }
 - }
 - if ( isset($thumb) && $thumb ) {
 - echo $thumb;
 - } else {
 - echo __(‘None’);
 - }
 - }
 - }
 - // for posts
 - add_filter( ‘manage_posts_columns’, ‘fb_AddThumbColumn’ );
 - add_action( ‘manage_posts_custom_column’, ‘fb_AddThumbValue’, 10, 2 );
 - // for pages
 - add_filter( ‘manage_pages_columns’, ‘fb_AddThumbColumn’ );
 - add_action( ‘manage_pages_custom_column’, ‘fb_AddThumbValue’, 10, 2 );
 - }
 
源代码出自:http://wpengineer.com/1960/display-post-thumbnail-post-page-overview/
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
                            
                            写给所有做网站的朋友的一封信
现在就开始执行“1+N”互联网推广和没有开始执行的人,一两天看不出任何区别; 一两个月看来差异也是微乎其微的;但在2-5年的长远时间来看的时候,你的高质量询盘不断增加,你的互联网资产已经建立完成,对手已经很难匹敌,现在你看到这段文字的时候就是最好的开始,现在就是最好的时候,马上开始“1+N”体系的整体互联网推广吧,我们和你一起,开创互联网大未来!
                            
                            
备案号: