Add column to pages table

时间:2011-09-07 作者:StealthRT

嘿,我正在试图找到编辑中的部分。php页面,其中用我当前的所有页面填充表。我想做的是在表中添加另一个列,以便启动用于更改图片的侧页。

enter image description here

有人能告诉我填充表的代码吗?

谢谢

大卫

2 个回复
最合适的回答,由SO网友:StealthRT 整理而成

我是这样做的:

/****** Add Thumbnails in Manage Posts/Pages List ******/
if ( !function_exists(\'AddThumbColumn\') && function_exists(\'add_theme_support\') ) {
    // for post and page
    add_theme_support(\'post-thumbnails\', array( \'post\', \'page\' ) );
    function AddThumbColumn($cols) {
        $cols[\'thumbnail\'] = __(\'Thumbnail\');
        return $cols;
    }
    function AddThumbValue($column_name, $post_id) {
            $width = (int) 60;
            $height = (int) 60;
            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\', \'AddThumbColumn\' );
    add_action( \'manage_posts_custom_column\', \'AddThumbValue\', 10, 2 );
    // for pages
    add_filter( \'manage_pages_columns\', \'AddThumbColumn\' );
    add_action( \'manage_pages_custom_column\', \'AddThumbValue\', 10, 2 );
}
以上代码摘自本页:http://wpmu.org/how-to-add-post-thumbnails-to-the-wordpress-post-and-page-management-screens/

SO网友:bueltge

还有一个教程,提供了在列中添加缩略图的page和post解决方案:http://wpengineer.com/1960/display-post-thumbnail-post-page-overview/将内容从缩略图更改为您的内容,并删除帖子挂钩:

// 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 );
后端中页面的id位于挂钩中,您可以在后端的所有表上添加新列,这也是多站点表的一个示例:http://wpengineer.com/2188/view-blog-id-in-wordpress-multisite/

    add_action( \'manage_sites_custom_column\', array( $this, \'add_columns\' ), 10, 2 );
    add_action( \'manage_blogs_custom_column\', array( $this, \'add_columns\' ), 10, 2 );

结束