Looking to display non-image files in Gallery with logo specific to file type

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

Read More

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.

Related posts

Leave a Reply

2 comments

  1. 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 )
    
  2. 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/