Media Tags 2.0 released
Filed Under: Tags: media-tags, plugins, WordPress
Today I would like to finally release to the wild the totally rewritten Media-Tags plugin version 2.0. The Media-Tags plugin 2.0 has been completely rewritten to use to WordPress Taxonomy system for storing related media-tag information. As a benefit to this rewrite the user now has a new Media Tags management interface located under the Media section. Via this Media Tags management interface users can better manage the media tags used on the site. Deleting, renaming and adding new media tags is now quite simple. The Media Tags for the attachment are still display both under Media and the media popup on the editor screen as before.
Some highlighted features in the new Media-Tags 2.0 release:
Media tags storage now using WordPress Taxonomy
In previous versions of the Media-Tags plugin the tag information was stored into the postmeta table. While this worked well it meant the tag information was only accessible in relationship to the post parent. The Media-Tags 2.0 version now uses the built-in WordPress Taxonomy system. Using this system greatly increases the flexibility of the media tag data. Using the standard WordPress functions get_terms() for example to directly query media tag information.
Permalinks Support
Because the media tags plugin now uses the WordPress Taxonomy system you can now access attachments archives via the new permalink tag ‘/media-tags/’. This is very powerful and one of the most requested features since the plugins initial release. An example of a media tag archive is something similar to
http://www.yoursite.com/media-tags/<media tag name>
where ‘<media tag name>’ is one media tag name from your site.
Media Tags Archive
Along the same lines as the new permalink structure you can now also use archive template files specific for media tags. By default WordPress will use the template file ‘archive.php’ if part of your theme. While this works fine you may also want to have a template file specific for displaying media tags archive. Introducing the ‘mediatags.php’ template file. The mediatags.php template is looks and functions much like a normal archive.php file complete with the header, footer, sidebar options as well as the standard WordPress loop. Actually my recommendation is to copy the existing archive.php to mediatags.php to start. Then add needed code to finish out the template file. Also you may define tag specific template files. Lets assume you have many media tags in your system. But one media tag, ‘bulk’, for example you want displayed a certain way. You can define a tag specific template file like ‘mediatags-23.php’ where ‘23 is the ID of that media tag. Please not the template file when used will display attachments not the parent post. In WordPress all uploaded media is part of a parent/child association. Unlike the normal post related template the media tag template display the actual media files.
Media-Tags Management interface
In version 2.0 of the Media-Tags plugin I’ve included a new management screen. When the plugin is activated you will see a new menu options ‘Media-Tags’ located under the top-level Media section. This management screen lets you add, delete, update media tags in your system. The interface should seem very familiar to user who use the WordPress Categories and Tags management screens.
Template functions
Also included as part of the plugin rewrite are some handy template tags to use via your theme. Below are a list of the template functions available. These are located in the plugin file mediatags_template_functions.php. All these functions should seem very familiar since they were modeled after the built-in WordPress tags template functions.
- is_mediatag() – Tests is we are displaying a media-tags archive. Much like is_category() function
- in_mediatag() – Tests is an attachment post marked in a certain mediatag_id.
- get_mediatags()
- list_mediatags() – Very handy for listing your media tags like list_tags() in the sidebar.php
- get_mediatag_link() – Given a mediatag_id this functon will return a link href value.
- the_mediatags() – Very much like the post-level the_tags() to display a comma separated list of tags for a given post item. Used then displaying media tags archives.
The original plugin function mediatags->get_media_by_tag(…) has now been replaced with a more simple non-object based template function get_attachments_by_media_tags(…). The original function has been deprecated and will be removed in future releases.
More options for Media-Tag Queries
The new Media Tags access function, get_attachments_by_media_tags(…), now supports many more parameters to let you filter the returned information better.
- media_tags: (Required) This is a comma separated list of tags you want to filter on.
- media_types: (Optional) This is a comma separated list of media types – gif, pdf, png to return
- post_parent: (Optional) This is the post ID of the related media items. This item is no longer required. This allows you to query media_tag items across all posts
- numberposts: (Optional) Default is all. Allows control over the number of items returned.
- orderby: (Optional) Default menu_order. See get_posts() for full list of options
- order: (Optional) Default ‘DESC’. Controls the order of items. Other option is ‘ASC’.
- offset: (Offset) Default is 0. Allows control over the subset of items returned.
- return_type: (Optional) Defaults to Array. Other option is ‘li’. In the case of shortcodes the return type is ‘li’ by default. When using the ‘li’ return type each element is given a class of ‘media_tag_list’ and an id of ‘media-tag-item-xxxx’ where ‘xxx’ is the attachment id.
- tags_compare: (Optional) Defaults to ‘OR’. When requesting multiple media_tags elements allow a compare between the lists of items returned. When using the ‘OR’ option returned item will be in one or more of the requested media_tags values. Other value is ‘AND’. When using ‘AND’ you are requesting only attachments which are in all requested media_tags.
Shorcode support
The media tags plugin now support the use of shortcodes. In its simplest form the media tag shortcode appears like
[media-tags media_tags="alt-views,page-full,thumb"]
Note you need to include quotes around the element value to ensure proper handling. The shortcode parameters available are pretty close to the direct function call. The exception is you need to specify the parameter name and value pairs.
[media-tags media_tags="alt-views,page-full,thumb" tags_compare="AND" orderby="menu_order"]
When using the shortcode option the return type is automatically set the ‘li’ which means list elements will be returned. When using shortcodes you can specific two parameters ‘before_list=’ and ‘after_list=’ to control the wrapper elements. Also, you can specify a new parameter ‘display_item_callback=’. This parameter will be a user defined function which allows you to control the output. The callback function will be called for each found element. Check the plugin file ‘mediatags_shortcodes.php’. There is a function used ‘default_item_callback()’ which is the default callback actually used by the plugin. Remember when using shortcodes in WordPress you MUST return every output. Do not echo information.
Lastly, when using the shortcode feature you may have a time when you need to specify the post_parent for the media_tags queried. Now you could add the post_parent ID directly to the shortcode settings. But then you would be hard-coding the ID for the given post. A better way is to just set the post_parent value to ‘this’. This will allow dynamic control over the shortcode processing.
[media-tags media_tags="alt-views,page-full,thumb" post_parent="this" before_list="<ul class='frank'>" after_list="</ul>"]
Download
As is customary the only place you should ever download released plugins is via the WordPress official plugin repository.
Download the new Media-Tags 2.0 plugin




July 21st, 2009 at 11:43 am
Thanks for your work on this new release! Unfortunately, I’ve been unable to get shortcode working… I want to show all the picture attachments for a person on his post, so I use this syntax:
[media-tags media_tags="person-name" before_list="" after_list=""]
And nothing happens. Am I doing something wrong?
Also, on the media tag admin page, when I click on the number of attachments I get nothing, like there were no one.
Again, thanks for your work and I hope the plugin ends up working for me too
July 21st, 2009 at 11:54 am
Carlos Will look into the shortcodes ASAP for you. Can you tell me what version of WordPress you are using?
As far as the number count on the new Media Tags admin interface this is the number from WP on the number of items with that tag. In the core WP this Taxonomy is tied to Posts and should take you to the Post listing page in wp-admin. The problem I can’t seem to solve with the number is that in the media-tagd world the count is Posts and Pages. I might just remove the link. I left it originally because it provides and indicator to the user how many times a media tag is used. Thus facilitating deleting dead media tags.
July 21st, 2009 at 12:33 pm
Hi Paul. I’m using the latest, WordPress 2.8.2. And regarding the number count link, do what you think is best. Thanks a lot for the quick answer.
July 22nd, 2009 at 6:27 am
Hi Paul
Firstly – Great Plug-in
I “Think” it is exactly what I am looking for, so I can categorize downlaodable documents.
I am a TOTAL Newbie (learn from a lot of trial and error). Do you have an example mediatags.php file that I can look at to learn how to modify my own?
Thanks Paul
Cheers
Ken
July 22nd, 2009 at 7:36 am
@Ken Hobson: If you take the default theme archive.php and copy it to mediatag.php in your current theme folder you should have a good start. There are no special tags needed for the template file. Just your normal loop function.
July 23rd, 2009 at 7:43 pm
Just pushed version 2.1.1 of Media-Tags to the WordPress repository. This new version (second one today) fixes a set of bug with the relative paths used to load the needed JavaScript libraries when WordPress is not installed into the site root.
Thanks to Ilan Y. Cohen for pointing out the error and providing suggestions on this fix as well as some other related modifications.
July 23rd, 2009 at 8:34 pm
Hi, I have only a trouble.
When I’m using this new taxonomy, it’s only working when I’m logged on my wordpress blog. When I logoff and try to access (for example: http://www.virtual.ufpb.br/wordpress/media-tags/biblioteca/) it’s saying that not found. :/
Anyway, thanks!
July 24th, 2009 at 4:27 am
I want the use the thumbnails and the link behaviour of the default [gallery] shortcode for a set of images I tagged with media-tags. I am already spending 4 hours to find a decent solution for this. I don’t think Media Tags can help me with this. No parameter displaying thumbnails or define link behaviour.
July 24th, 2009 at 7:27 am
@Francisco Ernesto Teixeira: Strange. Yes I just tried this on a fresh WP 2.8.2 install with a handfull of media-tag entries. Confirmed that this causes the 404 to be display. Ok. tracing the code. Hope to have a new patch up soon. Thanks for bringing this up.
July 24th, 2009 at 7:28 am
@Matthijs: Hmm. Have not thought about integration on interplay with the WP gallery code. When I have some time I’ll try and find a suggestion.
July 24th, 2009 at 8:31 am
Just pushed a new version of the media-tags plugin, 2.1.2 to the WordPress repository. This should solve the issue reported by Francisco Ernesto Teixeira http://www.codehooligans.com/2009/07/15/media-tags-20-released/#comment-42663
August 5th, 2009 at 5:37 am
Hello, like to say – it’s very nice plugin.
Few bugs that occured to me:
When gallery is searched it is done by //$get_terms_args['search'] = $search_term;
so slugs and NAMES dont match, cause $search_term is slug, and ['search'] do it by name
I got around with: $get_terms_args['slug'] = $search_term;
#2
It appears that if media-tag slug is same as some categories slug – $term_id in TERM_TAXONOMY will be the same as categories (wrong), so it can’t be filtered right.
What do you think would be quick fix for that?
Maybe prefix to slug?
Thanks, I appriciate your work.
Jozik
August 5th, 2009 at 8:24 am
@Jozik: Thanks for the comment. I’m not really sure where I pulled the get_terms_args['search'] from. Must have been some other plugins I was looking at. You are correct the correct parameter should be ’slug’.
I’m not sure on the second item. Will need to research.
August 6th, 2009 at 8:02 am
Paul, et. al,
This is a great plugin, and it’s theory should be integrated into the WP core — really great work.
One question, though:
On my mediatag.php archive page, how do I get the title of the current viewed tag to automatically appear?
e.g., at the top of the page I want it to say, “Images tagged as [dynamic name of media-tag requested]“.
For normal tag or category archive pages, there is a function, single_cat_title() and single_tag_title()
For now, I am just parsing the URL and extracting the title from there, but it’s not a pretty solution.
Once again, thank you!
August 6th, 2009 at 9:29 am
Carlos: Excellent question. Guess I forgot that in the template functions. Here is a little code snippet. I’ll be included this change in the next release next week of the Media Tags plugin. Thanks Carlos for the comment and suggestion.
Please add this to the bottom of the media tags file ‘mediatags_template_functions.php’.
function single_mediatag_title()
{
$mediatag_var = get_query_var(MEDIA_TAGS_QUERYVAR);
if ($mediatag_var) {
$mediatag_term = is_term( $mediatag_var, MEDIA_TAGS_TAXONOMY );
if (isset($mediatag_term['term_id'])) {
$media_tag = &get_term( $mediatag_term['term_id'], MEDIA_TAGS_TAXONOMY );
echo $media_tag->name;
}
}
}
Then you can call if from your mediatag.php template file like this (Or add the code to your archive.php provided from WordPress):
Posts Tagged ‘’
August 6th, 2009 at 11:28 am
Thanks Paul… worked perfectly!
Once again, great work with the plugin… beautifully executed.
August 6th, 2009 at 2:51 pm
Just upgraded to 2.1.3 – everything seems to work fine.
Thanks!
August 6th, 2009 at 3:30 pm
Thank you for your help.
August 14th, 2009 at 10:56 am
Great plugin , do you have any plans to add a tags col on the main lib page, like post?
August 14th, 2009 at 11:14 am
@John Turner: not sure I follow your message. I do plan to put in a Media Tag Cloud template function possibly this weekend. Does that answer your question? Sorry not sure what you meant be ‘tag col’.
August 21st, 2009 at 9:44 am
returns the tags without the proper syntax, i.e.
restoration
What would be the proper fix for a valid link? Thanks for a very needed plugin!
August 21st, 2009 at 9:45 am
August 21st, 2009 at 9:48 am
@David Radovanovic: That is strange. Appear it is not including the ‘/’ between your domain and the ‘media-tags’ permalink prefix. If you are running the plugin version 2.2 (the latest) you should be able to adjust this under Settings -> Permalinks. The new version of the plugin adds an input field at the very bottom and defaults to ‘media-tags’. Change your value to include the ‘/’ as in ‘/media-tags’.
August 21st, 2009 at 10:45 am
even with the /media in permalinks, “/” still is missing:
http://www.architecturalwebdesign.com/?attachment_id=90
August 21st, 2009 at 2:30 pm
If anyone is interested in the details of the solution for David let me know. I’ve patched the plugin code on his site and will include the patch in the next release of the plugin. Don’t really see a point in providing another release this week for such a minor fix. If your site is running the default permalink structure and you use the Media Tags plugin feel free to leave a comment here and I will pass you the changed files. Or just sit tight and wait for the next release.
August 22nd, 2009 at 2:25 pm
Sorry, let me clarify, If you click on post you’ll see a “Tags” column on the list view, I was wondering if you had any plans of adding a “Tags” column on the Media Library list view. If not, I’ll see if I can add it and contribute the code back.
August 22nd, 2009 at 2:44 pm
@John: Ah, Yes do plan on doing this eventually. Though not sure the Media list has hooks like the Pages and Posts lists. It’s on my list for an upcoming release.
August 24th, 2009 at 2:31 am
I’m using 2.2 version of your plugin and I’m having problems with my custom templates. I’ve hacked the site quite a bit and added some extra features with jQuery (1.3.2) and jQuery timers (1.1.3).
If I activate your plugin, jQuery timers fail to work (“jquery.timer is undefined”), if I deactivate the plugin everything works as it should.
August 24th, 2009 at 2:41 am
Ok, debuged it – had to move my includes under , since media-tags includes jquery in the head and that fizzles my other plugins. Perhaps you could alert other authors that your plugin needs jquery to work, as I’ve been digging for two days why my functions magically stopped working. (mental note: do a single change at a time, you’ll debug easier:))
August 24th, 2009 at 2:43 am
blog stripped my:
…under “wp _ head();” …
August 24th, 2009 at 8:23 am
@Luka Birsa: Thanks for the comment on this. I’m assuming you are referring to jQuery used for the front-end theme view and not the wp-admin view. At first I blew this off until I checked my code. Seems I am including jQuery on the front-end instead of just the wp-admin. This will be fixed in the next release this coming week. Here are the details of the bug.
If you open media_tags.php and view lines 74-82 you will see the line ‘wp_enqueue_script(‘jquery-form’);’ This is the only reference to jQuery in the entire plugin. The problem is this call is in the wrong place. The ‘init()’ is used by the theme ‘wp_head()’ function so as you are aware this means will insert jQuery into the front-end head. The change I just made was to move the ‘wp_enqueue_script(‘jquery-form’);’ line into ‘admin_init()’ function lines 84-88.
And just to be clean on this. The Media-Tags plugin does not require jQuery for any display for the front-end of the site. However the plugin does use jQuery for many of the screens in wp-admin. For this jQuery is already included. The jquery-form call is needed on the Media-Tags management screen for the Quick Edit function.
Finally thanks for the tip/advice on the ‘do a single change at a time, you’ll debug easier’.
August 27th, 2009 at 4:56 am
Great work & amazing plugin! I just updated from the beta version, changed the renamed functions and it’s working perfectly. Thanks again for your work. Best
August 30th, 2009 at 9:14 am
[...] verspreche ich mir jetzt von dem Plugin Media Tags 2.0 vom Codehooligan Paul Menard aus Austin, Texas. Google half mir ihn zu finden. Das Prinzip ist ganz [...]
August 31st, 2009 at 2:27 pm
[...] Media Tags 2.0 released Recent Comments [...]
September 30th, 2009 at 9:37 am
Great plugin, but not compatible with WP Security Scan, which overwrites WP Version. Could change the function is_MEDIA_TAGS_URL() ?
September 30th, 2009 at 11:10 am
@dreb: Thanks for the comment. Not sure how the plugin is effected by the WP Security Scan you are referring to. And not sure what you are requesting. Do you want me to rename the function?
October 5th, 2009 at 3:20 pm
[...] verspreche ich mir jetzt von dem Plugin Media Tags 2.0 vom Codehooligan Paul Menard aus Austin, Texas. Google half mir ihn zu finden. Das Prinzip ist ganz [...]
October 22nd, 2009 at 10:26 am
My school system was almost entirely white and generally middle class. ,
October 23rd, 2009 at 7:39 am
THAT would be a good use of a big carbon tax. ,
November 16th, 2009 at 4:36 pm
Hey Paul,
Great plugin. It’s letting me do some cool stuff in tandem with the jQuery Cycle plugin.
One question: it’s not clear to me how I’d grab the captions, etc. associated with an image. Is this possible with one of the existing functions, or even with some custom code?
November 16th, 2009 at 5:33 pm
@Ryan: There current aren’t any hook to all for display retrieval of the caption information via the Media Tags plugin. That is a great idea though. I’ll need to see about including that in the upcoming release.
November 17th, 2009 at 6:41 pm
Thanks for the quick response Paul. I did some searching and it doesn’t seem easy to do this manually; I’m not sure what WordPress functions you’d use to grab that info, but you could be the first person to figure it out!
November 17th, 2009 at 6:52 pm
@Ryan: I’m up for that challenge. So question on how you are using the Media Tags plugin. There are two basic way. View the template code or via the shortcode?
November 18th, 2009 at 10:58 am
Nice
I’m calling the function in the template.
March 4th, 2010 at 8:52 pm
Three suicide attacks in the central Iraqi city of Baquba kill at least 31 people, days ahead of parliamentary elections.