Custom attachments styling in post view

Retrieve the attachments

There’s a pretty unknown, but handy function in core: get_children();, which accepts an array of arguments. One of those is post_mime_type.

$attachments = get_children( array(
    'post_parent'    => get_the_ID(),
    'post_type'      => 'attachment', 
    'numberposts'    => -1,
    'post_status'    => 'publish',
    'post_mime_type' => 'application/msword'
) );

If you’re unsure about the MIME types of your doc files, you can simply call

var_dump( get_post_mime_type( get_the_ID() ) );

on your single.php (or whatever theme template displays your single attachments to see the exact MIME type.

Here’s a non complete list of possible MIME types for MS Word files:

.ext  | MIME Type
-------------------------------------------------------------------------------
.doc  | application/msword
.dot  | application/msword
.docx | application/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotx | application/vnd.openxmlformats-officedocument.wordprocessingml.template
.docm | application/vnd.ms-word.document.macroEnabled.12
.dotm | application/vnd.ms-word.template.macroEnabled.12

MarkUp

We then can puzzle together a list for them:

printf(
    '<ul><li></li></ul>',
    join( '</li><li>', wp_list_pluck( 'post_title', $attachments ) )
);