• Resolved vam2017

    (@vam2017)


    Hi. Thanks so much for such a good plugin. I was looking for different options. This plugin is the best.
    I have a question.
    I need to make a page with a gallery and a tag cloud.
    Here is the code:

    
    [mla_tag_cloud]
    taxonomy=attachment_tag 
    mla_link_href="[+page_url+]?current_id={+term_id+}"
    number=0 smallest=12 largest=12 separator=' / '
    [/mla_tag_cloud]
    
    [mla_gallery]
    tax_query= "array ( 0 => array ( 'taxonomy' => 'attachment_tag', 'field' => 'id', 'terms' => array( {+request:current_id+} ) ) )"
    mla_caption="{+image_alt+}" 
    columns=3 posts_per_page=20 size=full link=file 
    mla_link_class="nav-links"
    [/mla_gallery]
    
    [mla_gallery]
    mla_output="paginate_links,prev_next"
    mla_link_class="nav-links"
    tax_query= "array ( 0 => array ( 'taxonomy' => 'attachment_tag', 'field' => 'id', 'terms' => array( {+request:current_id+} ) ) )"
    columns=3 posts_per_page=20 size=full link=file
    [/mla_gallery]
    

    Everything works, but there is one problem.
    When I go to the gallery page for the first time, I see only a tag cloud, but there is no image gallery itself. After clicking on the tag cloud links, everything works fine.
    How to make the gallery visible immediately upon entering the page?
    I would be grateful for an example.

    Thanks a lot

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter vam2017

    (@vam2017)

    I forgot to say
    All images belong to the same Att. Category: mygallery

    Plugin Author David Lingren

    (@dglingren)

    Thanks for the positive feedback and for your question. Thanks as well for posting the complete source text of your shortcodes; very helpful.

    For your example, when the page loads without a current_id= query attribute the tax_query= parameters have an empty terms = array. This matches no items and gives an empty gallery result. The solution is to make the entire tax_query= value conditional on the presence of the {+request:current_id+} substitution parameter. When I tested this solution I discovered that the current MLA version does not allow empty tax_query= values, which I consider to be a defect.

    I have uploaded a new MLA Development Version dated 20200519 that allows and ignores empty tax_query= values. You can find step-by-step instructions for using the Development Version in this earlier topic:

    PHP Warning on media upload with Polylang

    It would be great if you could install the Development Version, update your shortcodes (see below) and let me know if you find any problems. Thanks for alerting me to this MLA defect.

    The [mla_tag_cloud] shortcode does not need any changes. To make your tax_query= values conditional you can use a content template as follows:

    [mla_gallery]
    tax_query= "{+template:(array \\( 0 => array \\( 'taxonomy' => 'attachment_tag', 'field' => 'id', 'terms' => array\\( {+request:current_id+} \\) \\) \\))+}"
    post_parent=all
    mla_caption="{+image_alt+}" 
    columns=3 posts_per_page=20 size=full link=file 
    mla_link_class="nav-links"
    [/mla_gallery]
    
    [mla_gallery]
    mla_output="paginate_links,prev_next"
    mla_link_class="nav-links"
    tax_query= "{+template:(array \\( 0 => array \\( 'taxonomy' => 'attachment_tag', 'field' => 'id', 'terms' => array\\( {+request:current_id+} \\) \\) \\))+}"
    post_parent=all
    columns=3 posts_per_page=20 size=full link=file
    [/mla_gallery]
    

    In the above example I have enclosed the query value with {+template:( … )+}. I have also added double backslashes before the parentheses inside the query so they are ignored by the content template processor. Finally, I have added post_parent=all so all of your items are displayed on the initial page load.

    You wrote “All images belong to the same Att. Category: mygallery“. I do not see any shortcode parameters reflecting this. You can try replacing the post_parent=all parameter with attachment_category=mygallery to filter the initial gallery display by the Att. Category value.

    I will leave this topic unresolved in case you have problems or further questions regarding installing the Development Version and updating your shortcodes. Thanks for your interest in the plugin.

    Thread Starter vam2017

    (@vam2017)

    Fine. Thank you so much!
    Updated the plugin as you said. Everything is working well.
    Below is the working code:

    [mla_tag_cloud]
    taxonomy=attachment_tag 
    mla_link_href="[+page_url+]?current_id={+term_id+}"
    number=0 smallest=12 largest=12 separator=' / '
    [/mla_tag_cloud]
    
    [mla_gallery] 
    attachment_category=mygallery
    tax_query= "{+template:(array \\( 0 => array \\( 'taxonomy' => 'attachment_tag', 'field' => 'id', 'terms' => array\\( {+request:current_id+} \\) \\) \\))+}"
    post_parent=all
    mla_caption="{+image_alt+}" 
    columns=3 posts_per_page=4 size=full link=file 
    mla_link_class="nav-links"
    [/mla_gallery]
    
    [mla_gallery]
    attachment_category=mygallery
    mla_output="paginate_links,prev_next"
    mla_link_class="nav-links"
    tax_query= "{+template:(array \\( 0 => array \\( 'taxonomy' => 'attachment_tag', 'field' => 'id', 'terms' => array\\( {+request:current_id+} \\) \\) \\))+}"
    post_parent=all
    columns=3 posts_per_page=4 size=full link=file
    [/mla_gallery]
    
    Plugin Author David Lingren

    (@dglingren)

    Thanks for trying the Development Version and confirming that it’s working for your application. Thanks as well for posting the updated source text do others can see it.

    The fix will also be part of my next MLA update, which you will get through the normal plugin update process.

    I am marking this topic resolved, but please update it of you have any problems or further questions regarding the conditional tax_query.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘MLA Gallery Shortcode’ is closed to new replies.