Для того, чтобы добавить столбец с миниатюрой в админку WordPress, совсем необязательно использовать плагины, есть вариант лучше. Немного подправив файл, вернее добавив нужную функцию мы вполне можем обойтись и без использования плагинов, т.к. каждый плагин по мимо нагрузки о которой все знают, еще и несет потенциальную угрозу в плане безопасности. Ну да ладно хватит лирики, к делу …. в файл functions.php добавим
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | 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) 100; $height = (int) 100; 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 ); } |
Это довольно таки старый способ, но до сих пор рабочий.
Есть еще один способ, он проще
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | add_filter('manage_posts_columns', 'posts_columns', 5); add_action('manage_posts_custom_column', 'posts_custom_columns', 5, 2); function posts_columns($defaults){ $defaults['thumbnail'] = __('Миниатюра'); $num = 2; return $defaults; } function posts_custom_columns($column_name, $id){ if($column_name === 'thumbnail'){ the_post_thumbnail( array(100, auto) ); } } |
Вот в принципе и все. Если нужно расположить столбцы в произвольном порядке, можно сделать так.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | //изменение порядка колонок в админке start function wph_column_order($columns) { $n_columns = array(); $move = 'thumbnail'; //передвигаем колонку 'миниатюра' $before = 'title'; //и ставим ее перед 'заголовком' foreach($columns as $key => $value) { if ($key==$before){ $n_columns[$move] = $move; } $n_columns[$key] = $value; } return $n_columns; } add_filter('manage_posts_columns', 'wph_column_order'); |