Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When I first began looking into this, File Gallery got me much closer to solving the problem. The only issue is that the plugin only displays the generic non-image icon when I upload a file.

Does anyone know of a pre-existing plugin that would either work alongside File Gallery or in place of it to achieve logos specific to a file type (say, I upload a .doc file then the plugin displays a MS Word logo).

Failing a pre-existing plugin, what would be a good starting point to attempt to craft my own hand-made solution?

Thanks in advance!

Note: This was originally posted in on the wordpress.org support forum here, but since it got no responses there, I thought I'd try my luck here.

share|improve this question
    
Just to follow up on this, following finding a solution to this I developed the Document Gallery plugin so if anyone else has a similar issue they are welcome to give it a try. –  Dan Jan 26 '13 at 2:30
add comment

2 Answers

up vote 2 down vote accepted

WordPress has a native function wp_mime_type_icon() in wp-includes/post.php that you can use.

Basic example:

// $attachment should be a full post object 

if ( wp_attachment_is_image( $attachment->ID ) )
{
    echo wp_get_attachment_image(
        $attachment->ID,
        array( 480, 900 ),
        FALSE,
        array ( 'class' => 'aligncenter' )
    );
}
else
{
    echo '<img src="' . wp_mime_type_icon( $attachment->post_mime_type ) . '">';
}

Look in wp-includes/images/crystal/ for available file type icons:

  • archive
  • audio
  • code
  • default
  • document
  • interactive
  • spreadsheet
  • text
  • video

enter image description here

You can set up your own image directory and filter 'icon_dir' for the local path and 'icon_dir_uri' for the URIs to let WordPress use your images.
To change just singular files filter 'wp_mime_type_icon':

apply_filters( 'wp_mime_type_icon', $icon, $mime, $post_id )
share|improve this answer
add comment

I don't think you will have luck getting it to work with another gallery plugin without altering that plugins code, but you can do this yourself rather easily by writing a plugin/function or using a template page.

What you can do is use get_children to grab the post_mime_type, in your case a simple example would be,

get_children( 'post_type=attachment&post_mime_type=doc' );
//assuming your using ms .doc files.

Once you have the mime type you can use wp_get_attachment_link to create the link, unfortunately this functions $icon parameter is a boolean so it does not allow you to add your own icon, you will have to echo out an actual url to the icon you want to use.

http://codex.wordpress.org/Function_Reference/get_children
http://codex.wordpress.org/Function_Reference/wp_get_attachment_link
http://tgrayimages.com/automate-file-attachments-on-your-wordpress-posts/

share|improve this answer
    
Thanks! This starting point will definitely help! –  Dan May 6 '12 at 0:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.