I am looking for easy styling list of .doc attachments in post. For example i want to put every in <li></li> tags and do some proper styling.

So far I am get my post content this way:

              while (have_posts()) : the_post();
  • 1
    Please provide information about what you've already tried. Commented Jun 6, 2013 at 7:59
  • in a code provided I am pulling posts content with atachments, but I am unable to do some styling with it> i want to have <li> tags around every atatachment Commented Jun 6, 2013 at 8:02

1 Answer 1


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


We then can puzzle together a list for them:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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