<?php
/**
* Post featured image column on admin post list page
*
* @wordpress-plugin
* Plugin Name: Post featured image column on admin post list page
* Description: Post featured image column on admin post list page.
* Version: 0.1.0
*/
//Get Featured image
function mts_get_featured_image($post_ID) {
$post_thumbnail_id = get_post_thumbnail_id($post_ID);
if ($post_thumbnail_id) {
$post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, 'widgetfull');
return $post_thumbnail_img[0];
}
}
function mts_columns_head($defaults) {
if (get_post_type() == 'post')
$defaults['is_featured_post'] = '<div class="dashicons dashicons-star-filled" title="'.__('Featured Post').'"></div>';
if (get_post_type() == 'post' || get_post_type() == 'page')
$defaults['featured_image'] = __('Featured Image', 'mythemeshop');
return $defaults;
}
function mts_columns_content($column_name, $post_ID) {
if ($column_name == 'featured_image') {
$post_featured_image = mts_get_featured_image($post_ID);
if ($post_featured_image) {
echo '<img width="150" height="100" src="' . $post_featured_image . '" />';
}
} elseif ($column_name == 'is_featured_post') {
if (get_post_meta( $post_ID, 'mts_featured', true )) {
echo '<div class="dashicons dashicons-star-filled" title="'.__('Featured Post').'"></div>';
} else {
echo '<div class="dashicons dashicons-star-empty" title="'.__('Not a Featured Post').'"></div>';
}
}
}
function mts_posts_admin_head() {
echo '<style type="text/css">';
echo 'td.column-is_featured_post, #is_featured_post { width: 20px; }';
echo '#is_featured_post .dashicons { color: #222; }';
echo '.column-is_featured_post .dashicons { color: #888; }';
echo '</style>';
}
add_action('admin_head-edit.php', 'mts_posts_admin_head');
add_filter('manage_posts_columns', 'mts_columns_head');
add_action('manage_posts_custom_column', 'mts_columns_content', 10, 2);
Post Featured image column on admin post list page
7 лет назад

