Home News Wordpress: Alter Custom Taxonomy Columns

Wordpress: Alter Custom Taxonomy Columns

by Phill

WordPress customized taxonomies are helpful for grouping wordpress articles and custom article kinds. By way of instance, tags and classes are standard taxonomies offered by WordPress to set WordPress items.

By producing our own customized taxonomieswe are able to creating our very own groupings of articles and custom article kinds.

WordPress additionally gives a standard user interface for handling our customized taxonomy objects. By way of instance, from the screen-shot below we show that the user interface to get our shiba_theme customized taxonomy object.

On the best, it exhibits the our listing of shiba_theme items, in addition to their titles, descriptions, slug, and related posts. In this situation howeverwe utilize the customized taxonomy description area to store a range of information connected with our subject item.

Thus, we wish to take out the description area and substitute it with the header picture related to each theme item.

We consider how to alter habit taxonomy user interface columns.

1. Produce shiba_theme Custom Taxonomy

We begin by creating our shiba_theme customized taxonomy object together with the register_taxonomy function.

1
2
3
4
5
6
7
8
if (!is_taxonomy('shiba_theme')) {
    register_taxonomy( 'shiba_theme', 'post',
               array(   'hierarchical' => FALSE, 'label' => __('Theme'), 
                    'public' => TRUE, 'show_ui' => TRUE,
                    'query_var' => 'theme',
                    'rewrite' => array('slug' => 'theme')
                    ) );
}

2. Alter Custom Taxonomy Columns

To alter our shiba_theme customized taxonomy columns we have to hook to the manage_edit-$taxonomy_columns filter.

manage_edit-shiba_theme_columns

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Add to admin_init function
add_filter("manage_edit-shiba_theme_columns", 'theme_columns');
function theme_columns($theme_columns) {
    $new_columns = array(
        'cb' => '<input type="checkbox" />',
        'name' => __('Name'),
        'header_icon' => '',
//      'description' => __('Description'),
        'slug' => __('Slug'),
        'posts' => __('Posts')
        );
    return $new_columns;
}

Line 8 — Insert a header_icon column for showing a thumbnail of this header picture connected with every shiba_theme object.
Line 9 — Don’t place the description column.

After we hook to manage_edit-shiba_theme_columns the description column becomes eliminated, but our header picture thumbnail still doesn’t get rendered.

3. Render New Custom Taxonomy Column Data

To leave our customized taxonomy header icon we all need to hook to the handle _$taxonomy_custom_column filter.

manage_shiba_theme_custom_column

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Add to admin_init function  
add_filter("manage_shiba_theme_custom_column", 'manage_theme_columns', 10, 3);
function manage_theme_columns($out, $column_name, $theme_id) {
    $theme = get_term($theme_id, 'shiba_theme');
    switch ($column_name) {
        case 'header_icon':
            // get header image url
            $data = maybe_unserialize($theme->description);
            $out .= "<img src=\"{$data['HEADER_image']}\" width=\"250\" height=\"83\"/>";
            break;
        default:
            break;
    }
    return $out;   
}

Line 6 — The column_name here corresponds to the column titles used within our theme_columns role in measure two.

After we do so, our header icon becomes left.

We’re Done!
We can use exactly the exact same procedure to add new activities to our customized taxonomy objects.

By way of instance, from the screen-shot over we’ve added the actions Pictures and Duplicate to our shiba_theme items.

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More