Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added attributes for orderby and order #2

Open
wants to merge 1 commit into from

2 participants

@kyled

Just added attributes for orderby and order so I could sort by menu_order. Updated version number.

@dougalcampbell

Just wanted to put a comment here so you wouldn't think I'm ignoring you or anything. :) I've just been busy. I'll probably incorporate this soon, and I have some other improvements in mind, as well.

Thanks for the pull request!

@kyled

Awesome. Look forward to seeing what improvements you bring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 3, 2012
  1. Added attributes for orderby and order

    Kyle De Almeida authored
This page is out of date. Refresh to see the latest.
Showing with 42 additions and 17 deletions.
  1. +13 −1 README.md
  2. +20 −15 documents-shortcode.php
  3. +9 −1 readme.txt
View
14 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
View
35 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 .= "<li class='$mime'><a href='$url'>$name</a></li>\n";
@@ -88,9 +93,9 @@ function dc_document_shortcode_init() {
function dc_document_shortcode_add_style() {
// Don't need plugin styles in dashboard
if ( is_admin() ) return;
-
+
$css_url = apply_filters( 'dc_document_shortcode_css_url', plugins_url( 'dc_documents.css', __FILE__ ) );
-
+
wp_register_style( 'dc_document_shortcode' , $css_url );
wp_enqueue_style( 'dc_document_shortcode' );
}
View
10 readme.txt
@@ -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
@@ -54,10 +54,14 @@ Examples:
Just application/pdf mimetypes:
`[documents mimetype="application/pdf"]`
+
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 +116,10 @@ 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.
Something went wrong with that request. Please try again.