WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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();
share|improve this question
Please provide information about what you've already tried. – Mike Madern Jun 6 '13 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 – Michał Lach Jun 6 '13 at 8:02

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 ) )
share|improve this answer

Your Answer


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.