diff --git a/README.md b/README.md index c63bce5..372eeed 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Donate link: http://dougal.gunters.org/donate Tags: documents, shortcode, documents shortcode, shortcode-only, files, attachments, pdf, word, excel, spreadsheet, text Requires at least: 2.5 Tested up to: 3.4.2 -Stable tag: 1.0.1 +Stable tag: 1.0.2 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -58,6 +58,11 @@ Examples: > All attached documents, regardless of type: > `[documents mimetype="*"]` +> Just application/pdf mimetypes sorted by menu order ascending: +> `[documents mimetype="application/pdf" orderby="menu_order" order="ASC"]` + + + ### I got an error trying to upload a file! If WordPress tells you that a file failed to upload due to an error ("Sorry, @@ -112,6 +117,13 @@ future, and I am open to suggestions. At this time, the only supported icon size is 32 x 32 pixels. ## Changelog + +### 1.0.2 +* Added attributes for orderby and order + +### 1.0.1 +* Allow CSS URL to be filtered. + ### 1.0 * Initial release. 2012-09-10 diff --git a/documents-shortcode.php b/documents-shortcode.php index fb3109f..41a64c3 100644 --- a/documents-shortcode.php +++ b/documents-shortcode.php @@ -4,7 +4,7 @@ Plugin URI: http://dougal.gunters.org/ Description: Shortcode to display a list of attached documents, optionally filtered by mime-type and/or file extension. Author: Dougal Campbell -Version: 1.0.1 +Version: 1.0.2 Min WP Version: 2.5 Author URI: http://dougal.gunters.org/ */ @@ -19,49 +19,54 @@ * * All .DOC, .DOCX, or .PDF files: * [documents ext="doc,docx,pdf"] - * + * * Only 'video' types with a .MOV extension: * [documents mimetype="video" ext="mov"] - * + * * Just application/pdf mimetypes: * [documents mimetype="application/pdf"] + * + * Just application/pdf mimetypes sorted by menu order descending: + * [documents mimetype="application/pdf" orderby="menu_order" order="DESC"] */ function dc_document_shortcode($atts) { extract(shortcode_atts(array( 'mimetype' => 'application', 'ext' => null, + 'orderby' => 'post_date', + 'order' => 'DESC' ), $atts)); - - $mime = "&post_mime_type=$mimetype"; - + + $mime = "&post_mime_type=$mimetype&orderby=$orderby&order=$order"; + $kids =& get_children( 'post_type=attachment&post_parent=' . get_the_id() . $mime ); if ( empty( $kids ) ) { return ''; } - + $exts = array(); - + if ( $ext ) { $exts = explode(',', $ext); $exts = array_map('trim', $exts); $exts = array_map('strtolower', $exts); } - + $documents = ''; - + foreach ( $kids as $id => $doc ) { $url = wp_get_attachment_url( $id ); - + $file = get_attached_file( $id ); $filetype = wp_check_filetype( $file ); $file_ext = strtolower($filetype['ext']); - + if ( count($exts) && ! in_array($file_ext, $exts) ) { // Not in list of requested extensions. Skip it! continue; } - + $name = $doc->post_title; $mime = sanitize_title_with_dashes( $file_ext ); $documents .= "