• Resolved alx359

    (@alx359)


    Greetings David,

    You have shared with us all a very powerful tool, and manifestly backed it with a stellar support!

    At glance, MLA should be capable of the requirements I have but frankly, feel overwhelmed with the so extensive options and technicalities I’m not familiar enough with.

    I’m asking for your kind direction of how one could achieve the requirements I have with MLA. Namely:

    a) Each image (media attachment) displayed in a gallery grid to be linked to the WC product they’re attached to (i.e. reading the ‘post_parent’ ID — part of attachment’s metadata — and extracting the corresponding page URL via WP core).

    b) Filtering queries to be dynamic, i.e. depending on the category/tags of the WC product that contains a given MLA gallery shortcode, the latter to render an individualized set of images (also filtered by att. categories).

    How would these be achievable with MLA?

    Thanks very much in advance and regards,
    Alex

Viewing 15 replies - 1 through 15 (of 17 total)
  • Thread Starter alx359

    (@alx359)

    Starting getting some answers by my own already:

    
    [mla_gallery attachment_category=wood-blocks posts_per_page=12 mla_link_href="?p={+post_parent+}"]
    
    [mla_gallery attachment_category=wood-blocks posts_per_page=12 mla_output="paginate_links,prev_next"]
    

    mla_link_href could be done less hackish apparently, but so far so good.

    Thread Starter alx359

    (@alx359)

    Another thing I’m not sure yet if achievable with MLA: non-flat tags.

    c) I’m using “Tag Groups” plugin for WC product tags (just enabling hierarchical tags seems to conflict with WC3). I already have populated MLA’s Att. Categories (imported from MCM via TMT), but wish to use MLA’s Att. Tags as well resembling WC’s. Is this possible?

    Thanks.

    Thread Starter alx359

    (@alx359)

    Missed the setting that “Tag Groups” sees the att. Tags taxonomy too, so groups are supported now. Hope MLA would play ball with them!

    PS. Just found an issue:
    When paginating a gallery residing in a lightbox (featherbox), hitting next page just closes the lightbox window, instead of loading the next page. How to fix this?

    Thread Starter alx359

    (@alx359)

    Ok, have come closer to crack the (b) part of the first post, but it seems an MLA advanced topic.

    1. Have already related media and product taxonomies at the meta-level, by term_group applied to their respective categories (thanks to Tag Groups plugin).
    2. Now I need to find the proper syntax to filter [MLA_gallery] images by term_group, i.e. show only those images where {(term_group->product_cat == term_group->attachment_category)|(term_group==misc)}

    Seems have to use the template syntax, but not sure yet how exactly. Writing this here so David may weight in before I may find a solution.

    Plugin Author David Lingren

    (@dglingren)

    Wow! Thanks for your kind words regarding MLA, for your questions and for all the work you have put in to experimenting and find your own answers. I feel that if I just keep watching this topic I will soon see that you have resolved everything on your own.

    Thanks as well for your patience in awaiting a response. I hope to give you some of the answers you seek.

    You wrote “Each image (media attachment) displayed in a gallery grid to be linked to the WC product they’re attached to …” I understand “WC” to mean WooCommerce; is that right? WooCommerce has been the subject of several earlier MLA support topics you might find useful:

    WooCommerce Fixt: is orderby product id available?

    Adding Product Category to Img Alt

    Can we get the url of an attachment parent?

    Regenerate Bulk “ALT TEXT” with “Product Name + Product Category + Keyword”

    In those topics you can see that “post_parent” might work, but it is not always reliable. The Woo Fixit plugin and the product: custom prefix might give you better results.

    Most of your work seems to do with the taxonomies that classify your products and/or Media Library items. I found the Tag Groups plugin by Christoph Amthor in the WordPress repository; is that the one? I am not sure what you mean by “(imported from MCM via TMT)“; are those other plugins?

    For “non-flat tags” have you considered using a hierarchical taxonomy like Att. Categories? That seems to be a more “WordPress-like” solution. I haven’t used the Tag Groups plugin and have no experience combining it with MLA.

    Finally, I am confused by your most recent post. Can you say more about “related media and product taxonomies at the meta-level” and provide an example? When you wrote “filter [MLA_gallery] images by term_group I understand that to mean “display all of the images assigned to any term in a specific term group” but that does not seem to be what you mean by “{(term_group->product_cat == term_group->attachment_category)|(term_group==misc)}“. I don’t know how to process a query that compares terms in one taxonomy to terms in another. Can you provide additional details and perhaps an example?

    I will look at your “lightbox (featherbox)” issue separately.

    Thanks for any further progress and clarifications you can provide.

    Thread Starter alx359

    (@alx359)

    Hey David, thanks for your answers! It’s reassuring to have you around while delving into the depths of this wonderful tool. 🙂

    Will study the links provided for a more reliable alternative to ‘post_parent’. Thank you!

    Regarding “related media and product taxonomies at the meta-level”, Here’s an example:

    Currently, an MLA gallery instantiated from inside a WooCommerce (WC) product looks like this:

    [mla_gallery attachment_category="wood-blocks" posts_per_page=16 size=medium mla_link_href="?p={+post_parent+}"]

    – Each of our WC products populates a WC product gallery of a single painting of ours crafted on varied blank items.
    – An MLA gallery opening in a lightbox is used to show a different view of the product not supported by WC, i.e., images of other similarly finished items that aren’t the WC’s featured images of the paintings themselves (i.e. woodblocks, jewel boxes, cards, etc.).

    However, attachment_category=”wood-blocks” is too broad of a term, as it doesn’t take into account the theme of the painting (e.g. icons, angels, mermaids, fairies, etc.) which populate the WC product category. So I’d need something like this:

    [mla_gallery attachment_category="wood-blocks && icons" posts_per_page=16 size=medium mla_link_href="?p={+post_parent+}"]

    One problem is that “icons” is a WC Category, not an Att. Category. So I need ‘icons’ in Att. Category as well to make a match.
    The other problem is, MLA opens from within a template plugin that’s common to all products, so I can’t just hard-code ‘icons’. I need:

    [mla_gallery attachment_category="wood-blocks && %WC_Category%" posts_per_page=16 size=medium mla_link_href="?p={+post_parent+}"]

    where %WC_Category% is the category of a given product the MLA gallery is being instantiated, which happens to be named the same in Att. Category.

    Hope it makes sense.

    PS. As ‘WC Category’ is quite elaborated, was looking for a way to simplify the link between both taxonomies and ‘Tag Groups’ by Christoph Amthor seemed indeed a good fit, but today discovered it’s creating an empty ghost ‘Category’ taxonomy in media that mirrors WC Category. Have to figure out another way but the premise remains the same.

    MCM: WP Media Category Management By DeBAAT
    TMT: Term Management Tools By scribu

    EDIT: ‘product:permalink’ is indeed looking better!
    [mla_gallery attachment_category="wood-blocks" posts_per_page=16 size=medium mla_link_href="{+product:permalink+}"]

    Thank you!
    Alex

    Thread Starter alx359

    (@alx359)

    Thought hard and experimented with a few approaches I could come up with in linking and re-organizing both taxonomies, but at the end of the day came back to the Tag Groups approach mentioned before as the most straightforward to our needs (interestingly, the ghost taxonomy issue didn’t happen this time). So I would be very thankful for your kind assistance in making this work as described in the previous post, i.e. something like:

    
    [mla_gallery attachment_category='"wood-blocks" {+term_group+}' posts_per_page=16 size=medium mla_link_href="{+product:permalink+}"]
    

    (Of course, if in your in-depth experience in this field you may suggest a different, simpler, or just more elegant WP approach, I’d be very keen to learn more about it.)

    Thank you!

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your updates and the additional information. I have installed all three of the plugins you mentioned on my WooCommerce test site to get a feel for them.

    It looks like Media Category Management duplicates functions already in MLA and is not needed. Are you still using it? If so, how/why?

    I am still struggling to understand the combination of Att. Category and “term_group”. Can you give me more information about which taxonomies you are using Term Group with and an example or two of a group and its terms?

    It looks like you want to compose a gallery of all items assigned to attachment_category=wood-blocks AND attached to products that are assigned to any product_cat term in a particular term_group. Is that right?

    You wrote “One problem is that “icons” is a WC Category, not an Att. Category. So I need ‘icons’ in Att. Category as well to make a match.” You could use a Woo Fixit tool, “Term Assignments for Media Library Items”, to copy terms from the WC product_cat taxonomy to the Att. Categories taxonomy. That tools could also be modified to suite your needs if I can understand them.

    I regret my confusion, but any additional details you can provide will help. Thanks for your patience!

    Thread Starter alx359

    (@alx359)

    Thank you for the effort and time spent on this. It’s really appreciated!

    I don’t use Media Category Management anymore. It indeed duplicates MLA.

    a) [term_group] creates a flexible link between Att. Category [attachment_category] and Product Category [product_cat] taxonomies, without the need one to mirror or pollute the terms of the other. [term_group] is just another view to the taxonomy trees, which allows one subset to match a different another in the other tree. Practically for us this means:

    b) [product_cat] is front-end, more complex, and leaning to the art motives and customer’s interests (angels, fairies, etc.). Also is a work in progress that may change often over time.

    c) [attachment_category] is back-end, simpler and leaning to the physically crafted products themselves (prints, woodblocks, cards, etc.). Also the terms used to describe the motives are broader and group a lot more stuff together that seldom changes in the seller’s (ours) point of view.

    d) Using [term_group] would allow us to keep that freedom of growing 2 different taxonomies without one polluting the other, and without some rigid or hackish structures (e.g. mirroring the simpler taxonomy (MLA) into the complex (WC) via a separate subtree and hiding it with CSS in the front-end).

    e) Extra bonus, [term_group+product_cat] gives us another “related products” feature different than WC’s.

    Example:
    term_group=”Angels,Asian,Ethnic,Fairies”
    attachment_category=”Angels(Angels), Asian(Asian), Ethnic(Ethnic), Fairies(Fairies), Jewelboxes, Prints, Woodblocks”
    product_cat=”Angels & Men(Angels), Icon Reproductions(Ethnic), She & Him(Ethnic), Asian Woman(Asian), Asian Collection I(Asian), Exotic Faces(Fairies)”
    etc.

    f) Note we don’t put the physical crafts (woodblocks, etc.) in the product_cat taxonomy on purpose at this time.

    Hope I managed to make a somewhat better case now?

    Anyway, I’m aware this is all perhaps a purely academic exercise as [term_group] seems out of the scope of MLA, by the former not being a custom type per se it seems. Thanks anyway for the time you spent trying to understand where I’m coming from with these strange requests 🙂

    Thread Starter alx359

    (@alx359)

    BTW, if handling term_group might not be feasible, is it there a chance to fix the pagination to work in a lightbox?

    Plugin Author David Lingren

    (@dglingren)

    Thanks for expanding your description of how you use Tag Groups in your application. Let me see if I understand your example.

    1. You have defined a Tag Group named ”Angels,Asian,Ethnic,Fairies”
    2. You have added seven attachment_category terms to the group, “Angels .. Woodblocks”
    3. You have added six product_cat terms to the group, “Angels & men … Exotic Faces”

    Is that right?

    For your application, you want to use a Tag Group to select terms you will use to filter the gallery. For example, you want to code something like:

    [mla_gallery attachment_category="Angels,Asian,Ethnic,Fairies"]
    

    and replace the Tag Group name with the seven attachment_category terms in the group. Is that right? If so, that is not too hard to implement.

    However, do you also want to:

    1. Find all terms in product_cat that are members of a Tag Group,
    2. Find all the WC products assigned to those terms, and
    3. Find all Media Library items used in those products as the product featured image or in the product gallery, then
    4. Add those items to the gallery display.

    This second part is much more difficult and may have serious performance complications. It is “hard” to go through the database and select the items associated with specific products. I understand the concern about “hackish structures” but this solution may be worse than the problem.

    If you want to include the second product_cat logic, is the connection between those items and the first items (assigned to the attachment_category terms) “AND” or is it “OR”? In other words, does an item have to be present in both sets to be included or in either one of the sets?

    You wrote “Extra bonus, [term_group+product_cat]” Does that mean you want “items assigned to attachment_category terms in the term_group but only those used in WC products assigned to a specific product_cat” or something else?

    It’s not Tag Groups that complicates things, it’s the “find media items associated with products” requirement. Does that make sense? All the Tag Group gives you is a name that can be translated into a list of taxonomy=term(s) clauses. I have some ideas for syntax but I want to make sure I understand the meaning first.

    Plugin Author David Lingren

    (@dglingren)

    I was unable to find a “featherbox” lightbox plugin, but I did find:

    WP Featherlight – A Simple jQuery Lightbox

    Is that it? If not, can you post a link to the plugin you’re using?

    You wrote “When paginating a gallery residing in a lightbox (featherbox), hitting next page just closes the lightbox window, instead of loading the next page. How to fix this?” I understand that to mean that you are using the [mla_gallery] shortcode with the mla_output parameter to generate pagination links on your post/page; is that right? If so, there may not be a good answer for this issue. The MLA pagination controls contain links that cause a complete page refresh when clicked. It’s hard to tell a lightbox control to automatically open up when the page is loaded. Usually the lightbox has JavaScript that hooks the gallery item links and uses them to open the lightbox when a link is clicked.

    If I know the specific lightbox I can have a quick look for a solution. Thanks for any additional information you can provide.

    Thread Starter alx359

    (@alx359)

    Hi David, thanks so much for your continuous interest in these issues!

    It seems you’re not familiar yet with the Tag Groups plugin, and this has lead to a certain disconnect and confusion in our conversation. My apologies!

    To get us both to a common ground, let’s see how to configure and make that plugin work first:

    a) After installment, we need to associate the taxonomies we want to group together from here:
    wp-admin/options-general.php?page=tag-groups-settings. In our case, those are product_cat and attachment_category.

    b) We need to add to the Tag Group *its own terms*. That happens in another GUI located here:
    wp-admin/edit.php?page=tag-groups. According to our example, those tag-group-specific terms are, separately: Angels, Asian, Ethnic, Fairies.

    c) Now we can group *category terms* belonging to the 2 different chosen taxonomies, in a *one-to-many relationship — per taxonomy*, where the “one” is a single Tag Group term, and the “many” – category term(s) belonging to each taxonomy. That happens from the “Categories” section for the given custom type. For product_cat in wp-admin/edit-tags.php?taxonomy=product_cat&post_type=product. We go and hit “Quick Edit” for a given term and assign it to a group via the dropdown. For attachment_category, we do the same in wp-admin/edit-tags.php?taxonomy=attachment_category&post_type=attachment.

    With the above all set up, let’s go again through our example.

    You have defined a Tag Group named ”Angels,Asian,Ethnic,Fairies”

    I have defined 4 different term_group tags.

    You have added seven attachment_category terms to the group, “Angels .. Woodblocks

    Not exactly. Those are attachment_category terms only. I have *assigned* term_group terms to those, as per described above.

    You have added six product_cat terms to the group, “Angels & men … Exotic Faces”

    As above, those are product_cat terms. I’ve *assigned* term_group tags to those.

    For your application, you want to use a Tag Group to select terms…

    For my application, I want to select a single term belonging to attachment_category with a single term belonging to term_group, in an AND association. For example: [mla_gallery attachment_category="woodblocks" term_group="angels"]

    Regarding the performance issues, I’m indeed not familiar yet with the WP DB structure, but I still imagine a more or less straightforward ‘select’ could do:

    
    SELECT attachment_category, term_group 
    FROM media.table
    WHERE attachment_category='woodblocks' AND term_group='angels'
    

    The only subtler trick would be reading term_group from the product the MLA gallery is being instantiated in, but one should be able to get that from ordinary product’s metadata. The “bonus” is we get an MLA gallery filtered by the different scope introduced in the sql relationship of above.

    Hope these clarifications are useful enough and would clear up the confusion!

    ***

    Regarding the featherlight lightbox, I haven’t used that plugin mentioned, because I recall there’s an issue with the featherlight version they use in the source. I took it from here: Featherlight JS

    and added it in functions.asp:

    
    /**
     *  Alternative lightbox functionality to workaround opening lightbox over quickview
     */
    add_action( 'wp_enqueue_scripts', 'ew_enqueue_scripts__featherlight' );
    function ew_enqueue_scripts__featherlight() {
        wp_enqueue_style ('featherlight-css', get_stylesheet_directory_uri(). '/assets/featherlight.min.css');
        wp_enqueue_script('featherlight-js',  get_stylesheet_directory_uri(). '/assets/featherlight.min.js', array('jquery'), '1.7.7', true);  
    }
    

    in style.css of child-theme (Flatsome) goes this:

    
    /* featherbox lightbox */
    /* overrides default styles via data-featherlight-variant */
    .ew-feather { background: rgba(256,256,256, 0.8); }
    .ew-feather .featherlight-content {
    	width: 85%;
        padding: 30px;
    	color: #666;
    	background: #fbfbfb;
        overflow-y: auto; /* scroll fix from nesting with quickview */ 
    }
    

    In the plugin I use for templating (woocommerce-tm-extra-product-options) goes this:

    
    <div class="similar-button"><a class="button white is-white is-small" href="#" target="_self" data-featherlight="#ew-similar-prints" data-featherlight-variant="ew-feather">More Prints <span class="special">❐</span></a></div>
    
    
    <div id="ew-similar-prints" class="ew-similar">
    <h2>Other Similar art as paper prints</h2>
    [mla_gallery attachment_category="a3-print" posts_per_page=16 size=medium mla_link_href="{+product:permalink+}"]</div>
    

    Thank you!

    Thread Starter alx359

    (@alx359)

    David, if you think it would better help to see this thing deployed, kindly contact me for admin access to <my-WP-username>@gmail.com. Thank you.

    Thread Starter alx359

    (@alx359)

    I’m sharing my solution to the issues described in this post. Thanks very much to David for his kind assistance, and chat off-site!

    1) Basic integration of ‘Tag Groups’ plugin with MLA
    The code below reads the term_group term(s) associated with the current product in single-product page and concatenates it with a single attachment_category term, in an AND association.

    
    /*********************************************************************/
    /**
     * Manage custom MLA syntax
     * https://wordpress.org/support/topic/group-of-wc-product/
     * https://wordpress.org/support/topic/feeding-mla-with-ids-via-hook-2/
     * Example Usage:
     * [mla_gallery attachment_category="a3-print" my_term_group=true]
     */
    add_filter( 'mla_gallery_attributes', 'ew_gallery_attributes', 10, 1 );
    function ew_gallery_attributes( $shortcode_attributes ) {
        if ($shortcode_attributes['my_term_group'] && $shortcode_attributes['attachment_category']) {
            // concatenate term1,term2
            $shortcode_attributes['attachment_category'] .= ew_term_group();
            // output all images where term1 AND term2. More complex queries will require of WP_Query syntax 
            $shortcode_attributes['tax_operator'] = "AND";
            // each category must be populated by itself. Children beneath aren't included
            $shortcode_attributes['tax_include_children'] = "false";
            unset( $shortcode_attributes['my_term_group'] );
        } 
    	return $shortcode_attributes;
    }
    /**
     * Add basic term_group support to MLA 
     * https://wordpress.org/support/topic/dynamic-links-and-filtering/
     */
    function ew_term_group() {
        global $product;
       
        // get all term_group ID's associated with the current product
        $product_terms = get_the_terms( $product->get_id(), 'product_cat' );
        // get all term_group labels
        $tag_group_labels = get_option( 'tag_group_labels', array() );
        // create an additional filter to feed back to MLA
        foreach( (array)$product_terms as $terms ) {
            if ( isset( $tag_group_labels[ $terms->term_group ] ) ) {
                 $mla_filter[] = $tag_group_labels[ $terms->term_group ];
                 shuffle( $mla_filter );
            } 
        }
        // return just a randomized first term to keep a simple MLA syntax
        // (otherwise a concatenated AND filter would become too narrow and get us nothing)
        return isset( $mla_filter ) ? ','.$mla_filter[0] : '';
    }
    

    2) ‘Featherlight JS’ integration with MLA Pagination
    I couldn’t make MLA pagination natively work in a lightbox, but fortunately it happened by itself with the help of the following plugin: Ajax Pagination and Infinite Scroll, by Malinky and the following paging settings in the plugin configuration:

    
    Posts (Content) Selector:   [#ew-similar-prints] or [div.gallery]
    Post (Item) Selector:       [figure.gallery-item]
    Navigation Selector:        [#ew-pagination-prints]
    Next Selector:              [a.next]
    

    Need to wrap MLA pagination in a named div, example:

    
    <div id="ew-similar-prints" class="ew-similar">
    <h2>Other Similar art as paper prints</h2>
    [mla_gallery attachment_category=prints-a3 my_term_group=true posts_per_page=4 size=medium mla_link_href="{+product:permalink+}"]
    <div id="ew-pagination-prints" style="display:none">
    [mla_gallery attachment_category=prints-a3 my_term_group=true posts_per_page=4 mla_output="paginate_links,prev_next"]
    </div>
    </div>
    

    Multiple MLA paginations can be used on the same page (as I do) if the wrapper is distinct.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Dynamic links and filtering’ is closed to new replies.