• Hello,

    I’ve set up multiple categories using Media Library Categories, and am looking for a way to display the category next to the icon to indicate the type of content it is. I saw in the docs that there are other options for filtering html content, but not for custom taxonomies or categories.

    Is this possible? Could you point me in the right direction?

    Thank you!

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • I am very much interested in this too!

    You can already get documents with specific categories from the shortcode options , so why not in the opposite direction, i.e an option to “Include x-taxonomy for documents”, just like there is an “include description” option.

    I have also hit a wall with this …

    I have just created a quick hack to do this.

    From this hack a complete functionality could easily be implemented in an actual release.

    This quick hack adds a term tag to each document-icon div like:
    (yes it could properly be renamed to either terms or categories for clarity)
    The tag will then be filled with a comma separated list of terms/categories.
    <div class="document-icon" term="OneCategory, AnotherCategory"></div>

    You can then easily with JS sort your documents, or extract the data from the tag to a badge or whatever.

    Either just replace your /inc/class-document.php file with this one:
    https://pastebin.com/tWMK7eeL

    Or do the few modifications below to get an overview of what is going on.

    Plugin edit how-to:

    1 ) in the plugins folder open the file /inc/class-document.php
    2) In the constructor ( the __construct function ) add this:

    $this->terms = wp_get_post_terms( $attachment->ID,'media_category');
    $this->terms = wp_list_pluck( $this->terms, 'name' );
    $this->terms = implode ("','", $this->terms);

    Remember to change media_category to whatever your taxonomy is named if it is different from this one from Enhanced Media Library.

    3) Then in the same file edit the __tostring function to add
    $this->terms
    To the $repl array
    '%terms%',
    To the $find array
    And last add
    terms="%terms%"
    To the div tag in the $doc_icon variable

    That’s it. You now get all the appropriate categories dumped in a tag for each document.

    ___

    EDIT (dirty front end hack to display the categories):

    Dump this js to your front-end to get some tags in your document-icon div extracted from the term tag:
    (requires jquery – bootstrap used for styling here)

                $('.document-icon').each(function (i) {
                    var t = $(this);
                    var terms = t.attr('terms');
                    if (terms !== undefined) {
                        var termsArr = terms.split(',');
                        console.log(termsArr);
    				}
    				termsArr.forEach(function(v){
                        t.append('<span class="badge badge-primary">'+ v + '</span>');
    				});
                });
    • This reply was modified 6 years, 4 months ago by jelixir.
    • This reply was modified 6 years, 4 months ago by jelixir.
    • This reply was modified 6 years, 4 months ago by jelixir.
    • This reply was modified 6 years, 4 months ago by jelixir.
    • This reply was modified 6 years, 4 months ago by jelixir.
    • This reply was modified 6 years, 4 months ago by jelixir.
    • This reply was modified 6 years, 4 months ago by jelixir.
    Thread Starter bremnerr

    (@bremnerr)

    Thats brilliant! I’ll give it a try tonight. Yes, I agree that this is absolutely a useful option to implement as part of the core functionality.

    I was actually looking to use this to create badges to indicate paid/protected content based on the category, so using classes is a great solution.

    No problem. What solution do you use to hide paid content with categories?

    I have gone with a JS solution that checks each document-icon>a[href] to check if the content is in a special members folder, it then displays a lock over the thumbnail if so and links to the login page instead of the file.

    You then move to that folder with the Media Library Folders plugin, if you want the specific file to be locked.

    To avoid direct linking that folder is then login protected through the servers nginx config with a special login check php file.

    But if there is an easier solution that would be preferable..

    • This reply was modified 6 years, 4 months ago by jelixir.
    • This reply was modified 6 years, 4 months ago by jelixir.
    • This reply was modified 6 years, 4 months ago by jelixir.
    • This reply was modified 6 years, 4 months ago by jelixir.
    • This reply was modified 6 years, 4 months ago by jelixir.
    Thread Starter bremnerr

    (@bremnerr)

    It’s a site I took over for a client and uses Memberships Pro 2. I like your solution though, its simple and elegant.

    I tried making your modifications and it throws an error. I’m going to go through and check syntax. I did change the media_categories to category to match with the proper taxonomy for Media Library Categories.

    Fatal error: Uncaught Error: Class ‘DG_Gallery’ not found in ../content/plugins/document-gallery/inc/class-document-gallery.php:26

    Thread Starter bremnerr

    (@bremnerr)

    Nevermind, as usual, I did something dumb, because reasons. All fixed now! Great work!

    Now to hide the class based on membership status of the logged in user ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add Category or Taxonomy to Details’ is closed to new replies.