Media Library is the images, videos, files, etc you upload and attach/insert into a Post or a Page. If you have so many media uploaded, it’s hard to manage or remember all of them because by default, WordPress doesn’t support Media Categories like Links or Posts.
On my blog, I’ve uploaded over hundreds of screen shots and source codes in attachments in order for my readers download and understand what I say easier. Without Media Categories, I’m always in trouble whenever I want to find a particular media file which was uploaded long time ago.
I researched a lot and found that there is a WordPress Plugin call Media Library Categories will help to organize your Media Library in Categories. This plugin is very easy to install, allow to create category as many as you want, easier for searching your media by filtering a category name. Every time you upload an attachment, you assign a category for it or you can [re]assign the category later via Edit Media function. And all your media can then be sorted per category, this is the function I like most.
Below are some screenshots I captured on my blog in order for you can preview:
1. Display Media Library In Categories Preview
As you can see, there is a new link called Media Categories under Add New link in Media box. On Media Library panel on the right, a new column named Categories show which category a media belongs to. And on the top, you can filter the list easier by selecting a category name in the Show All Media Categories drop down list.
2. Manage Your Media Categories
Currently, I created 2 categories: Screen Shots and Source Code. Basically, I can create as many as I want by clicking on Add Media Category button on the top. After that, just enter a name for the new category and you’re done.
3. Edit Or Add New Media Preview
Every time you add or edit a media, it allows you to select which category the media belongs to.
How to select all media files in a category
This is a extra part for those who are developers because you have to modify a little bit in your PHP template files. Let say you uploaded some images in a category with ID 4 then you want to display all those images in a particular post or a page template. To do that, just use/modify the PHP code below and replace tt.term_id=4 with your desired category id.
<?php echo "<ul>"; $count = 0; $banners = $wpdb->get_results(" SELECT p.*, a.term_order FROM rvsw_posts p inner join rvsw_term_relationships a on a.object_id = p.ID inner join rvsw_term_taxonomy ttt on ttt.term_taxonomy_id = a.term_taxonomy_id inner join rvsw_terms tt on ttt.term_id = tt.term_id where ttt.taxonomy=’media_category’ && tt.term_id=4 order by a.term_order asc; "); foreach ($banners as $banner) { $count++; echo sprintf("<li class=\"%s\">",($count == 1)?"active":""); echo sprintf("<img src=\"%s\" alt=\"%s\" border=\"0\" class=’top_banner’ style=\"display:none;\"/>",$banner->guid,$banner->post_title); echo sprintf("<div class=\"ft-title\">%s</div>",$banner->post_title); echo sprintf("</li>"); } echo "</ul>"; ?> |
In the PHP script above, $banner->guid will echo the image URL and $banner->post_title will echo the image title.
It’s cool, isn’t it. I uploaded a copy of the Media Library Categories plugin version 1.0.6 for you to download.
Your feedback or question is always welcome, just leave it in the comments.