Support » Plugin: Media Library Assistant » Show all pictures that have any attachment category

  • Resolved eljot22

    (@eljot22)


    Hi

    First of all, thanks you for MLA as this is great products with a lot of features. Nevertheless despite reading documentation and searchig the forum I was not able to achieve the following:

    1) how to dispaly all pictures that have any attachment category not empty? This is needed because I have in my library pictures like logos, icons and so on and they all do not have any attachment category. Using WP categories and attachment categories I can create different galleries, enhanced by cloud tags to show parts of them (current_id as attachment category id). I tried the following code (I’m not using standard gallery):

    [mla_gallery]
    attachment_category="{+template:({+request:current_id+}|+terms:attachment_category+}|no-category-found)+}"
    orderby="date DESC" posts_per_page=20 link="lightbox" width="300" height="300" columns=5
    mla_alt_shortcode="pt_gallery" mla_alt_ids_name=ids mla_alt_ids_template="media: {+alt_ids+}"
    [/mla_gallery]

    The idea was that as long as current_id is provided it is used as selected attachment category. When nothing is selected (default opening of a page) all attachment categories are show – and I do not want to hardcode them in the query. Lastly – empty page is shown if nothing is found.

    The above code is not working because – my guess is because of terms:attachment_category not returning values.

    2) MLA uses WP categories as taxonomy, but which exactly category it is? Currently in WP we have: posts categories, gallery categories, portfolio categories.

    Regards,
    Jarek

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for your positive comments about MLA and for an interesting question. Thanks as well for including the source text of your shortcode; very helpful.

    You can get the results you want by using the more powerful tax_query in place of the simple taxonomy query ( attachment_category=... ) shown in your shortcode text.

    This tax_query will show all items that have one or more terms assigned:

    tax_query="array(array('taxonomy'=>'attachment_category',operator => 'EXISTS'))"
    

    You could display all items that have no terms assigned by replacing “EXISTS” with “NOT EXISTS”.

    For your application, a Content Template can adjust the query to filter on current_id when it exists or default to the “EXISTS” query:

    tax_query="array( array( 'taxonomy'=>'attachment_category', {+template:('field'=>'slug', 'terms'=>'{+request:current_id+}')|'operator'=>'EXISTS'+} ) )"
    

    If current_id is present but the term does not exist an empty gallery will be displayed.

    The {+terms:attachment_category+} parameter only returns terms assigned to a specific item; it will not return all of the terms that exist in the taxonomy.

    You asked “which exactly category it is? MLA provides two custom taxonomies for your convenience, Att. Categories (attachment_category) and Att. Tags (attachment_tag). You can add any other taxonomies your site uses by checking the “Support” column in the “Taxonomy Support” section of the Settings/Media Library Assistant General tab. WordPress provides Categories (category) and Tags (post_tag). If you know the “slug” values for your “gallery categories” and “portfolio categories” taxonomies you can use them in place of “attachment_category” to filter on them instead.

    I hope that gets you the results you seek. I am marking this topic resolved, but please update it if you have any problems or further questions regarding the above suggestions. Thanks for your interest in the plugin.

    Thread Starter eljot22

    (@eljot22)

    Hi David

    Wow, that was pretty quick answer and it WORKS! ๐Ÿ™‚ Thank you so much ๐Ÿ™‚

    1) To make it more complex – I’m using tag cloud with url’s to provide current_id and on that basis reload page with filtered pictures. Here is my code:

    [mla_tag_cloud taxonomy=attachment_category number=0 mla_link_href="{+page_url+}?current_id={+slug+}"]

    This shows default cloud. Is there a way to add kind of ‘All’ link to the cloud that actually will reset my selection and sets current_id back to empty value?

    2) I found settings related to Support, thank you once again. And I also have a question here – is MLA capable of handing both Attachment Category and Gallery Category (WP) at the same time? So I would like to show images described with specific attachment category and assigned to WP gallery category? More or less like that (category_name here is configured so it is slug for WP Gallery Category):

    [mla_gallery category_name=world attachment_category=landscapes]

    Regards,
    Jarek

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with the good news and for the new questions. Thanks as well for your patience in awaiting a response.

    You wrote “Is there a way to add kind of โ€˜Allโ€™ link to the cloud…“. The [mla_term_list] shortcode supports option all/none elements, but there is nothing like this in the current [mla_tag__cloud] shortcode. It’s a good suggestions, and I will work on adding something to the next MLA version. I will post an update to this topic when I have progress to report.

    You asked “is MLA capable of handing both Attachment Category and Gallery Category (WP) at the same time?” You can use the parameters described in the “Simple Taxonomy Parameters” section of the Settings/Media Library Assistant Documentation tab to accomplish this. It’s a little confusing, but the category_name parameter in your example is an old WordPress convention. You must replace this with category, the actual taxonomy slug value. If you code:

    [mla_gallery category=world attachment_category=landscapes]
    

    You will get only those items assigned to both “world” AND “landscapes”. The default tax_relation that joins multiple taxonomy parameters is “AND”. If you code:

    [mla_gallery category=world attachment_category=landscapes tax_relation=OR]
    

    You will get all items assigned to “world” OR “landscapes”. You can find more information in the “Simple Taxonomy Parameters” section. If you have any problems or further questions regarding the above suggestions, post an update here.

    Plugin Author David Lingren

    (@dglingren)

    I am working on some enhancements to [mla_tag_cloud] and [mla_term_list] that will generate elements for selecting items with zero term assignments, one or more term assignments and zero or more term assignments (all items). These will take some time.

    In the interim, here is a simple trick you might find useful. You can add an [mla_gallery] shortcode above or below the cloud that will remove the current_id parameter from the URL. Try something like this:

    [mla_gallery post_mime_type="a-bad-type" mla_nolink_text='<a href="{+page_url+}">Reset the selection</a>']

    The โ€œtrickโ€ is using post_mime_type=”a-bad-type” to force an empty gallery, then using mla_nolink_text to generate whatever markup you want to add to the page.

    Let me know if this works for your application, and thanks for your patience.

    Plugin Author David Lingren

    (@dglingren)

    I have uploaded a new MLA Development Version dated 20210406 that adds special “option_all”, “option_no_terms” and “option_any_terms” values to the [mla_tag_cloud] and [mla_term_list] shortcodes. You can find information on adding them to your shortcode in the “Tag Cloud Display Content” and “Term List Display Content (all Output Formats)” sections of the Settings/Media Library Assistant Documentation tab.

    You can find step-by-step instructions for using the Development Version in this support topic:

    PHP Warning on media upload with Polylang

    It would be great if you could install the Development Version and let me know if it works for you. Thanks again for inspiring this MLA enhancement.

    Thread Starter eljot22

    (@eljot22)

    Hi David

    Thank you so much for you effort, I appreciate it so much. For a few days I’m unable to do any testing, but definitely I’ll to it and then let you know on results.

    Regards,
    Jarek

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.