List Attachments Shortcode v0.4a

This evening, I discovered a minor issue in version 0.3a of the List Attachments Shortcode plug-in. The problem was with the use of the orderby parameter. Because of some code related to the groupby parameter, the orderby parameter was ignored unless the groupby parameter was also set. This new version corrects that issue, so that you should be able to successfully use any of the orderby parameters available to the get_posts() function in WordPress.

Tip for Usage:

Since I mentioned the groupby parameter above, I thought I’d include a little tip on how to use it. This tip will most likely be included in the next version’s readme file.

When it comes to attachments in WordPress, the following labels translate to the following database fields:

  • The content of the Title field is stored in the “post_title” column in the database.
  • The content of the Caption field is stored in the “post_excerpt” column in the database.
  • The content of the Description field is stored in the “post_content” column in the database.

Therefore, if you are interested in grouping your attachments in specific sub-groups, you might want to use the “Caption” or “Description” field when uploading the attachments. Then, you would tell the shortcode to group your attachments by either “post_excerpt” or “post_content” (or, with newer versions of WordPress, you could just use “excerpt” or “content”).

For instance, let’s say you were posting a batch of stories written by three or four different authors. You could use the “Title” field to list the title of each document, then place the author’s name in the “Caption” field for each document. You would then use [list-attachments orderby="title" groupby="excerpt"] to display the attachments in a list grouped according to author, then organized by title.

9 thoughts on “List Attachments Shortcode v0.4a

    1. Curtiss Grymala Post author

      Do the documents have exactly the same excerpt? If not, they won’t be grouped together.

      I’ll try to see if I can figure out why it might only be showing 2 of your 3 attachments. I haven’t run into that before. Just to be sure, you’re not limiting the type of attachment that it should be displaying, are you?

      Reply
  1. Andy

    Hi Curtiss,

    I’m new to WordPress and am currently populating a site which has been built using list-attachments for displaying attachments. Forgive me if I have misunderstood this, but does the groupby function just group certain attachments together by tags within a full list of all of the page’s attachments?

    I’m trying to figure out a way of displaying only certain attachments (eg. with one author tag) in one place on a page, and others (with another author tag) elsewhere on the page. Is this possible, or can list-attachments only ever display one full list of all the page’s attachments as I have been led to believe by our new site’s developer?

    I’d appreciate an email if you can help me out – andy@fulbright.org.nz

    Cheers.

    Reply
    1. Curtiss Grymala Post author

      I’ll send this in an email in a moment, but wanted to reply publicly, too, in case anyone else has this question.

      At this time, the only way to filter the list of attachments is by file type. There is no easy way to limit the list of attachments by any other parameter.

      For that matter, I am fairly certain that the attachments inherit the author from the post, so all attachments in a post would have the same author, anyway; so there would be no way to split a list based on that particular item.

      You could try the Post Content Shortcodes plugin, though, which might be closer to what you’re trying to do.

      Reply
  2. Will

    Hi there,
    I have an issue with the way PDF files are sorted on our corporate Intranet, could you please advise if this plugin is suitable or could you possibly recommend another?

    Our corporate intranet is on a WP platform. We upload all our policies in PDF format using the Gallery. The Gallery itself doesn’t appear to be sortable alphabetically/numerically. It keeps stacking the list of documents according to the date each document has been uploaded.
    I would like to order all (PDF) forms alphabetically in ascending order
    I am currently using the Media Categories plug-in and I display company forms using short code such as this: [mediacategories categories=”22″]
    Thanks,
    Will

    Reply
    1. Curtiss Grymala Post author

      Will – Actually, if you really are trying to list all of the attachments on a specific post or page, you can use the gallery shortcode to sort things alphabetically. After you insert the [gallery] shortcode using the media window, you can add some parameters to it to adjust the way it sorts items. To sort from A to Z according to the attachment’s title, you can use [gallery order="ASC" orderby="title"].

      If you want a plain list of the attachments rather than the gallery look, you can definitely use my plugin to do so. You would use the same parameters as the gallery shortcode, so it would look like [list-attachments order="ASC" orderby="title"].

      If you’re trying to list all of the PDF documents in your media library, rather than just listing attachments to a specific post or page, you could also look at using my Post Content Shortcodes plugin. That allows you to specify a post_type (attachment) and post_mime_type (application/pdf) and list all of them together.

      Reply
  3. Curtiss Grymala Post author

    @wolf – There are a couple of things wrong with the shortcode you’re using. It should be:

    [list-attachments type="pdf" order="asc"]

    Notice that it’s a hyphen rather than an underscore in “list-attachments”, there are no commas in the correct version, and “ASC” needs to have quotes around it (and to be lowercase – which I intend to fix in the next version). Thanks.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *