Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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

35 changes: 20 additions & 15 deletions documents-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/
*/
Expand All @@ -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";
Expand All @@ -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' );
}
Expand Down
10 changes: 9 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.

Expand Down