Media Tags 2.0 released

July 15th, 2009 @ 11am : 45 comments : Socialize This
Filed Under: Tags: , ,

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

You can leave a response, or trackback from your own site.

45 Responses to “Media Tags 2.0 released”

  1. Carlos Says:

    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 ;)

  2. Paul Menard Says:

    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.

  3. Carlos Says:

    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.

  4. Ken Hobson Says:

    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

  5. Paul Menard Says:

    @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.

  6. Paul Menard Says:

    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.

  7. Francisco Ernesto Teixeira Says:

    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!

  8. Matthijs Says:

    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.

  9. Paul Menard Says:

    @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.

  10. Paul Menard Says:

    @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.

  11. Paul Menard Says:

    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

  12. Jozik Says:

    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

  13. Paul Menard Says:

    @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.

  14. Carlos Says:

    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!

  15. Paul Menard Says:

    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 ‘’

  16. Carlos Says:

    Thanks Paul… worked perfectly!

    Once again, great work with the plugin… beautifully executed.

  17. Carlos Says:

    Just upgraded to 2.1.3 – everything seems to work fine.

    Thanks!

  18. discounts Says:

    Thank you for your help.

  19. John Turner Says:

    Great plugin , do you have any plans to add a tags col on the main lib page, like post?

  20. Paul Menard Says:

    @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’.

  21. David Radovanovic Says:

    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!

  22. David Radovanovic Says:
    1
     <a href="http://www.architecturalwebdesign.commedia-tags/restoration" rel="nofollow">restoration</a>
  23. Paul Menard Says:

    @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’.

  24. David Radovanovic Says:

    even with the /media in permalinks, “/” still is missing:

    http://www.architecturalwebdesign.com/?attachment_id=90

  25. Paul Menard Says:

    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.

  26. John Says:

    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.

  27. Paul Menard Says:

    @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.

  28. Luka Birsa Says:

    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.

  29. Luka Birsa Says:

    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:))

  30. Luka Birsa Says:

    blog stripped my:

    …under “wp _ head();” …

  31. Paul Menard Says:

    @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’.

  32. Mothmenace Says:

    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

  33. Media Tags könnten helfen : Wiesel.lu Says:

    [...] 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 [...]

  34. Media Tags plugin for WordPress blogs « CodeHooligans Says:

    [...] Media Tags 2.0 released Recent Comments [...]

  35. dreb Says:

    Great plugin, but not compatible with WP Security Scan, which overwrites WP Version. Could change the function is_MEDIA_TAGS_URL() ?

  36. Paul Menard Says:

    @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?

  37. CI Says:

    [...] 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 [...]

  38. Loy15 Says:

    My school system was almost entirely white and generally middle class. ,

  39. Coder96 Says:

    THAT would be a good use of a big carbon tax. ,

  40. Ryan Says:

    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?

  41. Paul Menard Says:

    @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.

  42. Ryan Says:

    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!

  43. Paul Menard Says:

    @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?

  44. Ryan Says:

    Nice :)

    I’m calling the function in the template.

  45. prostonik_5 Says:

    Three suicide attacks in the central Iraqi city of Baquba kill at least 31 people, days ahead of parliamentary elections.

Leave a Reply