WordPress.org

Ready to get started?Download WordPress

Forums

Media Categories
[resolved] Echoing media by categories (2 posts)

  1. illathruz
    Member
    Posted 1 year ago #

    How can I simply echo the name and link of a non-image file(s) by category via php?

    For example, if I upload a pdf, assign a category to it, how can I then output it? normally, I would do something like

    <ul>
                                <?php
                                    $files =& get_children();
                                    foreach ((array) $files as $attachment_id => $attachment) {
                                        if(wp_get_attachment_link($attachment_id) != "Missing Attachment")
                                            {
                                                ?><li><?php echo wp_get_attachment_link($attachment_id); ?></li><?php
                                            }
                                    }
                                ?>
                            </ul>

    I have been searching this plugin page but cannot find a simple comprehensive documentation guide (probably because I'm new to wordpress... but still very comfortable with php).

    In "the other" wordpress Media Category plugin they have simple shortcodes like [mediacat cats="Documents"]. What is the usage here? Or if this question has already been answered, could you please direct me to that documentation?

    Much thanks.

    http://wordpress.org/extend/plugins/media-categories-2/

  2. Eddie Moya
    Member
    Plugin Author

    Posted 1 year ago #

    The only shortcode this plugin provides is a modified version of the[gallery] shortcode, where you can show a gallery of media by taxonomy like this: [gallery category="electronics"], where category can be replaced with any taxonomy name, and"electronics" is the term you want to filter by. See more about this on the 'Other Notes' section of the plugins page.

    Beyond that, so far I've left it to developers to use the same way they use other post types. You can use WP_Query, get_posts, and query_posts, by simply passing post_type="attachment". Just like you can when you get normal posts by category or other taxonomies.

    My intention is to be as un-intrusive, and fit in with how WordPress normally functions as possible. I would probably never add functionality that would specifically output a list of links, because thats not a common use, and because I would not want to create limitations as to how this plugin gets used.

    One thing I do intend on doing in the near future is to add filter to let theme developers change the markup and styles for galleries. I also want to add a 'template' parameter to the gallery shortcode - so that theme developers can give their users a choice of multiple templates. Using this, you would able to create a simple template that made resulted in a list of links rather than the default WordPres gallery. Since I would be making this pluggable - this is the only case where I might package the plugin with a template that outputs links.

    Thats down the line though, for now you would have to do it the way you have above.

    You should also know that you can use the link="file" parameter in the gallery shortcode to turn make the gallery images link to the file rather than an attachment page. This is the default behavior of the Gallery Shortcode.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.