广告投放

如何给WordPress后台文章列表,添加缩略图

目录

    如何给Wordpress后台文章列表,添加缩略图

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

    如何给Wordpress后台文章列表,添加缩略图

    将如下代码添加到当前主题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 );
    }
    声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

    给TA打赏
    共{{data.count}}人
    人已打赏
    广告位招租919838898
    0 条回复 A文章作者 M管理员
      暂无讨论,说说你的看法吧
    个人中心
    购物车
    优惠劵
    今日签到
    有新私信 私信列表
    搜索