Add_custom_column

WordPress only shows a few built-in columns. Codepress Admin Columns plugin will give you many additional columns.

function product_edit_columns($columns){
$columns = array(
“cb” => “<input type=\”checkbox\” />”,
“title” => “Product Name”,
“description” => “Description”,
“Size” => “<b>Size</b>”,
“Price” => “<b>Price</b>”,
“Brand” => “<b>Brand</b>”,
“name” => “<b>Name</b>”,
“Category” => “<b>Category</b>”,

);

return $columns;
}

function product_custom_columns($column){
global $post;

switch ($column) {
case “description”:
the_content();
break;

case “Price”:
echo get_the_term_list($post->ID, ‘Price’, ”, ‘, ‘,”);
break;
case “Brand”:
echo get_the_term_list($post->ID, ‘Brand’, ”, ‘, ‘,”);
break;
case “name”:
echo get_the_term_list($post->ID, ‘name’, ”, ‘, ‘,”);
break;

case “Category”:
echo get_the_term_list($post->ID, ‘Category’, ”, ‘, ‘,”);
break;

}
}

//=============OR=================//

add_filter('manage_edit-gallery_columns', 'add_new_gallery_columns');
function add_new_gallery_columns($gallery_columns) {
    $new_columns['cb'] = '<input type="checkbox" />';
    
    $new_columns['id'] = __('ID');
    $new_columns['title'] = _x('Gallery Name', 'column name');
    $new_columns['images'] = __('Images');
    $new_columns['author'] = __('Author');
    
    $new_columns['categories'] = __('Categories');
    $new_columns['tags'] = __('Tags');
    $new_columns['date'] = _x('Date', 'column name');
    return $new_columns;
}

 // Add to admin_init function

add_action('manage_gallery_posts_custom_column', 'manage_gallery_columns', 10, 2);
function manage_gallery_columns($column_name, $id) {
    global $wpdb;
    switch ($column_name) {
    case 'id':
        echo $id;
            break;
    case 'images':
        // Get number of images in gallery
        $num_images = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = {$id};"));
        echo $num_images;
        break;
    default:
        break;
    } // end switch
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s