• Resolved diesel33

    (@diesel33)


    Hello everybody, hello David (developer) and congrats for your plugin.

    It is awesome to use the shortcode for displaying images, but I am stuck in something I believe should be quite simple:

    I wanna be able to show a gallery with images from my blog, but filter them on WP categories, i.e., be able to show all images that have been uploaded to posts belonging to a certain category, say ‘Colombia’.

    With the taxonomy methods and using shortcodes like
    [mla_gallery category=”colombia”]
    or
    [mla_gallery attachment_category=”colombia”]
    I only get 0 results:

    My blog is old and have like 2800 images uploaded before I installed mla plugin. So all images in media library have no categories associated (or att_categories) and it is absolutely impossible for me to go thru all and set categories for them.

    So my goal is to be able to select all images that have been uploaded to posts on a certain category. This must be possible because, in the media library, I can see all media items have a field on the right that says the post they belong to.

    I am sorry I couldn’t find any option to attain this thru the complexity of mla settings and documentation, I guess it should be straighforward. I am willing to code as far as I can in the native code, if it comes necessary and I have your guide, David or followers.

    Thanks all and have a cool day today.

Viewing 15 replies - 1 through 15 (of 21 total)
  • Thread Starter diesel33

    (@diesel33)

    By the way, the purpose is to use on a form
    mla_term_list
    to show the WP categories (and probably do the same with tags) on a dropdown and then click to filter on same page or another. So the slug of the category/tag should be received on target page and use mla_gallery shortcode with it…
    pretty much like in the example of documentation.

    Cheers!

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your kind words and for your question.

    The best solution for your application is to assign the appropriate terms to each of your Media Library items. You wrote “So all images in media library have no categories associated (or att_categories) and it is absolutely impossible for me to go thru all and set categories for them.” Here is an earlier topic that outlines two solutions to resolve the “absolutely impossible” part of your problem:

    Sync category from parent post to media

    You could use the first solution to map your “parent_terms:category” term assignments to the childrens’ attachment_category terms or add category support to the attachments and then map them to the childrens’ category terms. I prefer to use a separate taxonomy for Media Library items but either approach will work.

    I encourage you to consider this alternative. I will leave this topic unresolved for now so you can update it. Let me know if this works for you or if there’s a reason to pursue your original idea. Thanks for your interest in the plugin.

    Thread Starter diesel33

    (@diesel33)

    Hi David,
    thanks for your rapid reply, it is awesome to see there’s already a workaround for it and motivation is back!

    The first issue I have is that I can’t install any of the example plugins suggested in that topic, cause when I click on the ‘Example plugins button’, it lands on the page only saying that typical error message of WP,
    ‘Are you sure you wanna do this?’
    ‘Try again’

    The url is
    wp-admin/options-general.php?page=mla-settings-menu-documentation&mla_tab=documentation&mla-example-search=Search&_wpnonce=438845bb87

    This could be because my version of WP is old and I don’t upgrade it because I have made a lot of changes in native code thru the years and everything would be messy without them.

    I hope there’s another way to install those? ??
    Maybe uploading the files of plugings thru ftp?
    Is there a way to find a zip or something like with raw plugins?

    The plugin examples are
    MLA Substitution Parameter Hooks Example
    and
    Smart Media Categories

    Thanks so much David.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with the additional information.

    As you wrote, 3.5.1 is pretty old and I haven’t tested the example plugin install with that version. I’ll go back and do that at some point.

    In the interim you can install the examples manually. All of the example plugins are in the media-library-assistant/examples/plugins/subdirectory. Look there for:

    mla-substitution-parameter-hooks-example.php – single file
    smart-media-categories – this is a subdirectory

    You can FTP those to your /wp-content//plugins/ directory or, if you package them into a ZIP archive, use the “Upload plugin” button on the Plugins/Add New admin screen.

    Let me know if you need more detailed instructions. Good luck!

    Thread Starter diesel33

    (@diesel33)

    David,
    Good news about installing; easily I installed both plugins thru ftp and activated them.

    I tried the first approach (with mla-substitution-parameter-hooks-example) but I got a little bit lost in the IPTC/EXIF tab with rules and templates so I went for the easy,

    The second example plugin (smart-media-categories) was, as for the user from the original topic, easy to work. I read thru the pdf with instructions and got a few posts individually synced with their attachments.

    Things should go smooth now, no reason to not click on the challenging ‘Sync all children’ button, but one thing;

    I’ve noticed that the system finds children attachments of posts by their parent ID, this seems to be the post they were “uploaded to” (as in the original media library ‘All’) or “attached to” (as it says in your Media Library Assistant).
    I understand this association is made when you upload new files when writing a post -or page-, i.e. from the ‘Add new’ page (for posts in this scenario).

    I regret I have quite often uploaded bunches of pictures at the same time when redacting the same post, even if they would end up being INSERTED in different posts, just to batch the whole thing while I wrote.

    This means many of my pictures are ATTACHED to a post (children of it) now in wrong posts, and if I SYNC all, some pictures would end up with taxonomy categories they don’t belong to.

    Just correct me if I am wrong.

    Also I wonder if there’s a way to use those fields (Featured in,Inserted in,Gallery in), cause, as you can imagine, the 100% accurate solution in my project would be to give children only the parent’s categories where they were INSERTED, meaning, where they were linked, on the post body, with an html tag.

    Many times the attachments (images, children) are unattached, they have no parent, I wonder if I uploaded them from the main gallery page and not from a post. In those cases, the fields Featured in,Inserted in,Gallery in, are informed and could be super useful.

    Let mew know your thoughts, and always grateful!

    Thread Starter diesel33

    (@diesel33)

    I have a little extra question now:

    When declaring the navigation links for pagination, it is necessary to pass by url params the number of page and the current category; As you know url params are separated by ampersand symbol &.

    In the shortcode, ampersand is not recognized and pagination links are messed.

    mla_link_href='{+new_url+}?mla_paginate_current={+new_page+} -> & <- current_item={+query:category,text+}'

    Link generated is like:
    ?mla_paginate_current=2#038;current_item=everest

    How to write that ampersand so it doesn’t mess? I tried &amp; and also & #038; but it messes still more ??

    I wonder if any of the options in this page will help:
    https://www.toptal.com/designers/htmlarrows/punctuation/ampersand/

    By the way, in the code above, can not current_item parameter be also
    {+request:current_item+}
    instead of
    {+query:category,text+}
    ?

    Thanks for your time !!

    Plugin Author David Lingren

    (@dglingren)

    Thanks for trying out the example plugins and for the update about your experience.

    As you discovered and reported, the Smart Media Categories solution works best when strict discipline has been applied to the practice of attaching items to the appropriate parent. Neither of the solutions I suggested help find and process items that are “inserted in”, “featured in” or used in a gallery in a post or page. In part, that’s because is not uncommon to use an item in more than one post/page and there’s no automatic way to determine the appropriate “parent”.

    You can use the “where-used” information to assist a manual process of assigning terms, e.g., use the “Select Parent” popup link in the “Attached to” column to update the item based on what you see in the where-used column(s). I understand that may not be convenient or even practical in your application.

    It’s possible to use the hooks built in to MLA to create a small custom plugin that uses the where-used information to assign a parent. Whether this is useful depends on the specifics of your application. In particular, are your items inserted or used in exactly one post/page? Or, failing that, is there an automatic way to determine which post/page to assign as the parent? For example, should they be assigned to the oldest post/page they appear in, or the most recent post/page, or some other rule?

    You can also decide between two approaches. First, you could use the rules to “attach” the item(s) to the appropriate parent. Second, you could simply copy the terms from the appropriate post/page to the item without setting/changing the item’s parent. Which one works for your application?

    If you can give me more information about what rules your application requires I can look at creating an “example plugin” solution for you. Let me know if that’s of interest.

    Regarding your extra question, in my testing the plain, unescaped ampersand character works fine in the mla_link_href parameter. For example, here’s a shortcode I prepared for a recent support topic:

    displaying PDF documents

    You can see the shortcode for the pagination controls towards the bottom of that example. I assume you’re using the “Text” tab of the editor, not the “Visual” tab.

    It’s possible that WP 3.5.1 works differently, but that seems unlikely. It would be very helpful to see the complete source text of your shortcode or the entire post/page it appears in. That would also help me answer the current_item parameter question as well. Thanks for any additional information you can supply.

    Thread Starter diesel33

    (@diesel33)

    David, I am grateful for the time you take to specifically reply all our questions. Your willing to code custom plugins for specific user requirements is so generous ??

    1.- I believe I have never used the same picture in two posts or pages. So there would be no issue with deciding which ‘insert’ would be more imperative. The where-used fields like inserted-in give me, indeed, tips for manually re-assigning parents to wrong childrens. But it is not always the same that’s informed. It varies from children to children, sometimes it is featured-in, sometimes gallery-in…
    Between your two approaches, I believe the first is more ideal.
    I think I am not in shape for coding a plugin and I don’t wanna make you work too much in this. In the end, it is literally too expensive to go thru all my media library assigning right parents or categories but it would anyway be my job ??
    Please proceed with coding only if it is an easy thing and challenges you.

    2.- The &.
    Something tricky. It changes even the order of parameters depending on how I write it. My code is:

    <form id="mla-text-form" action="." method="post" class="row">
    <strong>Categoría:</strong>
    [mla_term_list taxonomy=category mla_output=dropdown mla_markup=cat-dropdown mla_option_value="{+slug+}" show_count=true]
    </form>
    
    [mla_gallery category="{+template:{+request:current_cat+}+}" posts_per_page=12 post_mime_type=image/jpeg mla_output="paginate_links,show_all" mla_link_href="?mla_paginate_current={+new_page+}&current_cat={+request:current_cat+}"]
    
    [mla_gallery category="{+template:{+request:current_cat+}+}" posts_per_page=12 post_mime_type=image/jpeg link=file mla_itemwidth="172px !important" mla_margin="20px 10px" mla_caption="{+caption+}" mla_rollover_text="{+title+}"]
    
    [mla_gallery category="{+template:{+request:current_cat+}+}" posts_per_page=12 post_mime_type=image/jpeg mla_output="paginate_links,prev_next" mla_link_href="?mla_paginate_current={+new_page+}&current_cat={+request:current_cat+}"]

    Note that I have cat-dropdown dropdown declared in the settings page with submit ‘onChange’ and current_cat as parameter field between navigations.
    Note that I have two pagination outputs, above and below, for easier navigation. One shows all pages, another prev_next links.

    The first pagination (with & a m p ; even if code above shows same) makes the pages url like:
    ?amp;current_cat=india&mla_paginate_current=2

    The second (using only a plain ampersand like your examples) like:
    ?mla_paginate_current=2#038;current_cat=india

    I always use text window and not visual wondow for editing posts.

    3.- NOTE: the only thing I’ve changed from your code is the template part.
    You separate with a | the second part, ‘bad_term’, for displaying gallery empty if no dropdown item selected. I wanted to show all items with no filter when page is first displayed and no category is selected, so I tried ‘all’ after the | and then I just deleted it with it’s corresponding brackets. It ends like:
    category="{+template:{+request:current_cat+}+}"
    and still it is empty on first display.

    Could you tell me how to show whole gallery on first display (like with post_parent=all but within this example)?
    And more important, can you tell me if this code change I’ve done could be responsible of the ampersand thing? ??

    I don’t believe so: everything works great but the pagination urls, as described above.

    4.- Finally, I wonder if I can display anywhere on page, outside mla shortcodes, the name of the category that has been selected, as improval for UX, user experience. Otherwise user sees pictures but nowhere says what pictures are, even the dropdown is reset to initial value.

    See it all in
    https://www.yomelargo.com/galeria/categorias/

    Thanks mate!

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with all the additional information.

    I have set up a test system running WordPress 3.5.1 and PHP 5.6.34. Quite a trip down memory lane!

    With these old versions I loaded your code to a page and I have reproduced the odd mla_href ampersand behavior. I will investigate further to see if I can find the cause and (I hope) a fix. I will post an update here when I have progress to report.

    Thanks for your patience while I dig deeper.

    Plugin Author David Lingren

    (@dglingren)

    I have made some progress. I found a fix for the ampersand problem requiring a small change in the MLA code. However, you can get immediate relief with a few changes to your existing code. Try using this new version:

    <form id="mla-text-form" action="." method="post" class="row">
    <strong>Categoría:</strong>
    [mla_term_list taxonomy=category mla_output=dropdown mla_markup=cat-dropdown mla_option_value="{+slug+}" show_count=true]
    </form>
    
    [mla_gallery category="{+template:({+request:current_cat+})+}" posts_per_page=12 post_parent=all post_mime_type=image/jpeg mla_output="paginate_links,show_all" mla_link_href="?current_cat={+request:current_cat+}"]
    
    [mla_gallery category="{+template:({+request:current_cat+})+}" posts_per_page=12 post_parent=all post_mime_type=image/jpeg link=file mla_itemwidth="172px !important" mla_margin="20px 10px" mla_caption="{+caption+}" mla_rollover_text="{+title+}"]
    
    [mla_gallery category="{+template:({+request:current_cat+})+}" posts_per_page=12 post_parent=all post_mime_type=image/jpeg mla_output="paginate_links,prev_next" mla_link_href="?current_cat={+request:current_cat+}"]
    

    I made these changes:

    1. Added parentheses in the templates, e.g., ({+request:current_cat+}) to supply an empty value when the current_cat is not present.
    2. Added post_parent=all to display all the items when the category is empty.
    3. Removed the mla_paginate_current={+new_page+}& parameter to avoid the ampersand problem. This parameter is automatically added by MLA so you don’t need it in your shortcode.

    Give these changes a try and let me know how they work for you.

    Plugin Author David Lingren

    (@dglingren)

    You wrote:

    4.- Finally, I wonder if I can display anywhere on page, outside mla shortcodes, the name of the category that has been selected, as improval for UX, user experience. Otherwise user sees pictures but nowhere says what pictures are, even the dropdown is reset to initial value.

    There are a few solutions you can explore:

    1. You can modify the PHP template file your theme uses to display the page, taking the current_cat value and looking up the corresponding term name.
    2. You can use am MLA custom markup template for your gallery that displays the term name in a gallery header of some sort. I can prepare an example of this approach if you are interested.
    3. You can use the “MLA UI Elements Example” plugin to make the dropdown selection “sticky”. More details are in this earlier topic and the other topics it links to: keep selected dropdown value after submit.

    I am still researching your first question; thanks for your patience.

    Thread Starter diesel33

    (@diesel33)

    Hey David;

    All good news;

    Your code works as expected.
    I decided now tags are not efficient filtering cause parent of a tag has also other absolutely different tags and pictures end up mixing ‘sunrises’ with ‘adventure’ for example.

    So I put all in same page (https://www.yomelargo.com/galeria/) and initially shows all pictures, then filters per category if selected. I think it is going well.

    I had to install little plugin for executing php snippet code on post/page body so I could echo the current_cat param wheter coming thru POST or GET, if informed. This was tricky because it didnt allow special chars to be submitted and updating page with shortcodes failed always. So I went to the raw WP database and put the php code there as snippet and after a few trials (unicode neither allowed to put single quotes ‘) I got it working, you can check online.

    I am super grateful for all your help and time involved.

    Let me know if you see any way with my first question, and otherwise I’ll sync all media items with parent terms with the button on MLA assistant page.

    ?? ?? ??

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update and the good news about the shortcode changes I suggested. I also enjoyed your remarks about the PHP snippet adventures – sorry it was so colorful. Can you tell me which plugin you used for that? I’m curious about how it works.

    Regarding your first question, I am having a fresh look at one of my existing example plugins, “MLA Insert Fixit” (mla-insert-fixit.php). The current version has a couple of “Attach Media Library items” tools you might find useful:

    • Attach Inserted In – Attach items to the first Post/Page they are inserted in
    • Attach Featured In – Attach items to the first Post/Page for which they are the Featured Image

    In the current version these tools only operate on unattached items. I could add an option to apply them to ALL inserted/featured items if that would be of use to you.

    The plugin also has a “Copy Parent values to attached Media Library items” section that includes an “Item Terms to Parent” tool (not what you want).

    I am thinking about adding a new tool to the “Copy Parent Values …” section that would copy assigned terms from a parent’s taxonomy to the item’s taxonomy. That would be like a simpler, one-time alternative to the Smart Media Categories “Sync All” operation. Would that be of interest?

    An alternative would be to copy assigned terms to inserted/featured items without altering their attached to/parent status. Would that be better?

    Let me know what you think about the above alternatives.

    Thread Starter diesel33

    (@diesel33)

    Hey David.

    Those plugins were “Insert PHP Code Snippet” and “Insert PHP”, both simple and not too updated, so making them suitable for my old version of WP. You can add snippets in the first, then calling them with a specific shortcode in post/page, or just use php special tags around your php code in the second.

    I used some logic to get $_POST or $_GET param and show the text.

    So this “MLA Insert Fixit” will work, if you add option, on all attached and unattached items of media library, therefore updating all items that are already wrongly attached to a parent post, to the post where the item (picture) is first found inserted in the post body? As an < i m g s r c = “” / > tag I guess?
    And similar for featured?

    This could be nice to do before I click on the smart-media-categories sync-all-items button. That way the parents would be correctly assigned to media pictures, and therefore convenient terms would be inherited.

    That “Copy Parent values to attached Media Library items” sounds exactly like what we want, like the button I just mentioned, the ‘sync-all-items’ on the smart-media-categories example plugin.
    Why do you first say it is not what I want? If it is not developed yet, as your next paragraph indicates, and if it would be better than the sync-all, then it definitely would be of interest!!

    Thanks again David!!

    Plugin Author David Lingren

    (@dglingren)

    Thanks for the PHP plugins sources and for your thoughts on the Insert Fixit improvements.

    The “not what you want” comment was referring to the existing tool, which copies terms from the Media Library item up to the parent post/page – the opposite direction of what you want. As you mentioned, you want to copy terms from the parent to the item.

    I am traveling for a few days and away from my development system, but I will be working on these enhancements next week. Thanks for your patience.

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘mla shortcode to show images of all posts of a WP category’ is closed to new replies.