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.

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:

 <?php
              query_posts('cat=13');
              while (have_posts()) : the_post();
              the_content();
              endwhile;
            ?>
share|improve this question
1  
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
add comment

1 Answer

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