• Resolved cristiano771

    (@cristiano771)


    <form id="mla-text-form" action="." method="post" class="row">
    <strong>UCCELLI</strong>
    [mla_term_list taxonomy=attachment_category mla_output=dropdown mla_option_value="{+slug+}" child_of="127" show_count=true pad_counts=false hierarchical=true depth=0 ]
    
    <br>   <br>
    <input id="text-form-submit" name="text_form_submit" type="submit" value="Visualizza le immagini">
    </form>
     
    [mla_gallery]
    attachment_category="{+template:({+request:tax_input.attachment_category+}|no-term-selected)+}"
    posts_per_page=25 mla_output="paginate_links,prev_next" orderby=date order=DESC
    mla_link_href="'{+new_url+}?mla_paginate_current={+new_page+}&tax_input[attachment_category]={+query:attachment_category,url+}'"
    [/mla_gallery]
     
    [mla_gallery attachment_category="{+template:({+request:tax_input.attachment_category+}|no-term-selected)+}" posts_per_page=25 orderby=date order=DESC mla_caption="{+title+} : {+description+}" mla_nolink_text="<br>Seleziona una categoria per visualizzare le immagini corrispondenti.<br>" 
    mla_link_href="/richiedi-stampa/?current_id={+attachment_ID+}"]

    I am using this code for my page in which an user can select an image of my galleries and ask for a print.
    The dropdown shows the sub-categories child of term 127.
    How could I insert in my page a second dropdown list for showing the main categories and then pass this value to the main term list? For example, if the user select a main category with term_id=100 the dropdown term list can show all terms child_of 100?
    I hope my poor english could be enaugh to explain my answer.
    Thank you,
    Cristiano

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

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

    (@dglingren)

    Thanks for an interesting question. Thanks as well for including the full source text of your form and shortcodes and the link to your page; very helpful.

    I have worked out a solution for your request. Here are a form and shortcodes that are working on my test system:

    <form id="mla-text-form" action="." method="post" class="row">
    <strong>UCCELLI</strong>
    [mla_term_list taxonomy=attachment_category mla_output=dropdown parent=0 mla_control_name=main_category mla_item_parameter=current_main_category show_count=false use_filters=true]
    <br>
    [mla_term_list taxonomy=attachment_category mla_output=dropdown mla_option_value="{+slug+}" child_of="{+template:({+request:main_category+}|1)+}" mla_control_name=sub_category mla_item_parameter=current_sub_category show_count=true hierarchical=true depth=0 use_filters=true]
    <br>
    <input id="text-form-submit" name="text_form_submit" type="submit" value="Visualizza le immagini">
    </form>
     
    [mla_gallery]
    attachment_category="{+template:({+request:sub_category+}|no-term-selected)+}" 
    posts_per_page=25 mla_output="paginate_links,prev_next" orderby=date order=DESC
    mla_link_href="{+new_url+}?mla_paginate_current={+new_page+}&main_category={+request:main_category+}&sub_category={+request:sub_category,url+}"
    [/mla_gallery]
     
    [mla_gallery attachment_category="{+template:({+request:sub_category+}|no-term-selected)+}" posts_per_page=25 orderby=date order=DESC mla_caption="{+title+} : {+description+}" mla_link_href="/richiedi-stampa/?current_id={+attachment_ID+}" mla_nolink_text="Seleziona una categoria per visualizzare le immagini corrispondenti."]
    

    I have made a number of changes to your shortcodes so either copy the above text as-is or be very careful when you update your text.

    I have added a second dropdown control at the top of the form, using the mla_control_name=main_category and mla_item_parameter=current_main_category parameters to give it unique names. This control uses the parent=0 parameter to select all the main categories, the top-level terms, in the taxonomy. If you have top-level terms that should be excluded from the list you can add parameters to achieve that. The show_count=false parameter disables adding the number of term assignments to this list.

    I have modified the original shortcode to accept the value selected in the top control:

    child_of="{+template:({+request:main_category+}|1)+}"
    

    The template accepts the main category when it is present and substitutes 1 when it is not, so the control is not displayed until a main category is selected. I have added the mla_control_name=sub_category and mla_item_parameter=current_sub_category parameters to give unique names.

    You will see a new parameter, use_filters=true, added to both [mla_term_list] shortcodes. This is used by the “MLA UI Elements Example” plugin I added to the application; it retains the values selected in the dropdown controls when the page is refreshed. You will find instructions for adding this plugin to your application below.

    I have changed the data selection parameter in both of the [mla_gallery] shortcodes to attachment_category="{+template:({+request:sub_category+}|no-term-selected)+}", using the name from the second term list control. I have also changed the mla_link_href parameter to use the unique names of both term list controls:

    mla_link_href="{+new_url+}?mla_paginate_current={+new_page+}&main_category={+request:main_category+}&sub_category={+request:sub_category,url+}"
    

    During my testing I discovered two MLA defects that prevented the above example from working properly. I have fixed these defects and uploaded a new MLA Development Version dated 20211108 that contains the corrected code. You can find step-by-step instructions for using the Development Version in this earlier topic:

    PHP Warning on media upload with Polylang

    Once the Development Version is installed you must install and activate the example plugin. Navigate to the Settings/Media library Assistant Documentation tab and click the “Example Plugins” button. Type “elements” in the text box and click “Search Plugins” to filter the table.

    You are looking for the “MLA UI Elements Example” plugin. Find that plugin and hover over the title in the left-most column. Click the “Install” rollover action, then go to the WordPress Plugins/Installed Plugins submenu and activate the example plugin as you would any other plugin.

    Once the Development Version and new example plugin are installed and active you can use the source text I provided above to update your page. The updated code will be part of my next MLA version, but in the interim it would be great if you could install the Development Version and the example plugin and let me know if they work for you. I will leave the topic unresolved for now. Thanks for your patience while I developed this solution.

    Thread Starter cristiano771

    (@cristiano771)

    <form id="mla-text-form" action="." method="post" class="row">
    <table>
    <tr><td colspan="3">È possibile selezionare, dalle categorie principali, gli ordini o le specie da visualizzare. La seconda selezione mostra le thumbnail della specie. Cliccando su ciascuna thumbnail è possibile richiedere la stampa della foto.</td></td>
    <tr>
    <td>Selezione Categoria / Specie</td>
    <td>
    [mla_term_list taxonomy=attachment_category mla_output=dropdown mla_control_name=main_category child_of="400" mla_item_parameter=current_main_category show_count=false use_filters=true depth=1 hierarchical=true use_filters=true]
    <br/>
    [mla_term_list taxonomy=attachment_category mla_output=dropdown mla_option_value="{+slug+}" child_of="{+template:({+request:main_category+}|1)+}" mla_control_name=sub_category mla_item_parameter=current_sub_category show_count=true hierarchical=true depth=0 use_filters=true]
    </td>
    <td>
    <input id="text-form-submit" name="text_form_submit" type="submit" value="SELEZIONA">
    </td>
    </tr>
    </table>
    </form>
     <br/>
    [mla_gallery]
    attachment_category="{+template:({+request:sub_category+}|no-term-selected)+}" 
    posts_per_page=25 mla_output="paginate_links,prev_next" orderby=date order=DESC
    mla_link_href="{+new_url+}?mla_paginate_current={+new_page+}&main_category={+request:main_category+}&sub_category={+request:sub_category,url+}"
    [/mla_gallery]
     
    [mla_gallery attachment_category="{+template:({+request:sub_category+}|no-term-selected)+}" posts_per_page=25 orderby=date order=DESC mla_caption="{+title+} : {+description+}" mla_link_href="/richiedi-stampa/?current_id={+attachment_ID+}" mla_nolink_text="Seleziona una categoria per visualizzare le immagini corrispondenti."]

    Thank you so much! I have just modified something:
    The first dropdown has child_of="400" and use_filters=true depth=1 hierarchical=true use_filters=true so it shows the main categories but not the category “ALL” (I use just to count all images). With depth=1" the dropdown is much more user friendly.

    Now I have a second question!
    Could I replicate the code to have a third dropdown? (so I could show one level of sub-categories for each dropdown).

    Thank you a lot for your kindness and you so useful job!
    Cristiano

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with the positive feedback, your progress report and the new question. The updated page on your site looks great!

    Adding a third control to show a three-level hierarchy might be possible as long as every “Specie” has at least one child term. A user will have to select a value in all three controls to display a gallery. It will not be possible to, for example, select PAESAGGIO and then only select “paesaggio montano” to see the “mountain landscape” images in all of the third-level categories. Does that make sense, and is that acceptable?

    I am also unsure what will happen when the user changes the main Categoria control. I think the second level should be updated and displayed while the third level and the gallery should disappear. Does that make sense, and is that acceptable?

    If the above solution and limits are acceptable I can investigate further. Thanks for any additional details you can provide.

    Thread Starter cristiano771

    (@cristiano771)

    Thank you for the answer. I understand the problems that the user could have if I add a third control. My problem is just that the main category “UCCELLI” (birds) has many sub-categories (families) that have many sub-sub-categories (species). This produce a very long dropdown menu… I was thinking to separate the selection of “birds” in a new page so I could use just only two controls. But… how can I automatically navigate to a new dedicate page when the user select the main category “UCCELLI”? Is there a solution for this?

    I am really happy to have your support! I’m managing to customize the interaction with my galleries exactly as I wanted … Thank you so much!

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your post with the additional details on what you have in mind. Thanks as well for your patience in awaiting my response.

    There is no easy way to “automatically navigate to a new dedicate page when the user selects the main category” but I have worked out an alternative that might work for you. I have added two more dropdown controls to the existing page. Now there is one main level control, two second level controls and one third level control. Depending on the main category selected only one of the two second level controls is displayed. If the “UCCELLI” category is selected, making a selection on the second level will cause the third level control to be displayed. For any other main category, selecting the second level will display the gallery.

    For your site I found this option for the UCCELLI category:

    <option class="term-list-term term-list-dropdown-term level-0" value="127">UCCELLI</option>
    

    I have used the “127” value in the source text below. If that’s not right you can make an adjustment. The [mla_gallery] shortcodes have been updated to use either the second level or third level term, whichever is present. Here is the code working on my system:

    <form id="mla-text-form" action="." method="post" class="row">
    <strong>UCCELLI</strong>
    [mla_term_list taxonomy=attachment_category mla_output=dropdown parent=0 mla_control_name=main_category mla_item_parameter=current_main_category show_count=false use_filters=true]
    <br>
    [mla_term_list taxonomy=attachment_category mla_output=dropdown include_tree=127 child_of="{+template:({+request:main_category+}|1)+}" mla_control_name=include_category mla_item_parameter=current_include_category show_count=true pad_counts=false hierarchical=true depth=1 use_filters=true]
    <br>
    [mla_term_list taxonomy=attachment_category mla_output=dropdown mla_option_value="{+slug+}" exclude_tree=127 child_of="{+template:({+request:main_category+}|1)+}" mla_control_name=sub_category mla_item_parameter=current_sub_category show_count=true pad_counts=false hierarchical=true depth=0 use_filters=true]
    <br>
    [mla_term_list taxonomy=attachment_category mla_output=dropdown mla_option_value="{+slug+}" include_tree=127 child_of="{+template:({+request:include_category+}|1)+}" mla_control_name=third_category mla_item_parameter=current_third_category show_count=true pad_counts=false hierarchical=true depth=0 use_filters=true]<br>
    <input id="text-form-submit" name="text_form_submit" type="submit" value="Visualizza le immagini">
    </form>
     
    [mla_gallery]
    attachment_category="{+template:({+request:sub_category+}|{+request:third_category+}|no-term-selected)+}" tax_include_children=false
    posts_per_page=25 mla_output="paginate_links,prev_next" orderby=date order=DESC
    mla_link_href="{+new_url+}?mla_paginate_current={+new_page+}&main_category={+request:main_category+}&sub_category={+request:sub_category,url+}"
    [/mla_gallery]
     
    [mla_gallery attachment_category="{+template:({+request:sub_category+}|{+request:third_category+}|no-term-selected)+}" tax_include_children=false posts_per_page=25 orderby=date order=DESC mla_caption="{+title+} : {+description+}" mla_link_href="/richiedi-stampa/?current_id={+attachment_ID+}" mla_nolink_text="Seleziona una categoria per visualizzare le immagini corrispondenti."]
    

    The limitation of this approach is that it only works for one three-level tree.

    To make this code work I had to make some minor changes to the MLA core code. I have uploaded a new Development Version dated 20211122 that includes the updates. You can follow the process outlined in the earlier topic to download and install the new Development Version. The example plugin is unchanged and does not need to be updated.

    It would be great if you tried this new approach and let me know how it works for you. Thanks!

    Thread Starter cristiano771

    (@cristiano771)

    Thank you so much, David. I apologize for the delay in my reply, I had a difficult week … I just tried your update and your new code. I just made a few small changes (so I have eliminated the ALL category, that I use just for a total count of my images).
    This is my final code:

    <form id="mla-text-form" action="." method="post" class="row">
    <table>
    <tbody>
    <tr>
    <td width="25%" valign="top">Categoria / Specie: </td>
    <td width="50%">
    [mla_term_list taxonomy=attachment_category mla_output=dropdown child_of="400" mla_control_name=main_category  depth=1 mla_item_parameter=current_main_category show_count=false use_filters=true]
    <br>
    [mla_term_list taxonomy=attachment_category mla_output=dropdown include_tree=127 child_of="{+template:({+request:main_category+}|1)+}" mla_control_name=include_category mla_item_parameter=current_include_category show_count=true pad_counts=false hierarchical=true depth=1 use_filters=true]
    <br>
    [mla_term_list taxonomy=attachment_category mla_output=dropdown mla_option_value="{+slug+}" exclude_tree=127 child_of="{+template:({+request:main_category+}|1)+}" mla_control_name=sub_category mla_item_parameter=current_sub_category show_count=true pad_counts=false hierarchical=true depth=0 use_filters=true]
    <br>
    [mla_term_list taxonomy=attachment_category mla_output=dropdown mla_option_value="{+slug+}" include_tree=127 child_of="{+template:({+request:include_category+}|1)+}" mla_control_name=third_category mla_item_parameter=current_third_category show_count=true pad_counts=false hierarchical=true depth=0 use_filters=true]</td>
    <td width="25%" valign="top">
    <input id="text-form-submit" name="text_form_submit" type="submit" value="SELECT">
    </td>
    </tr>
    </tbody></table>
    </form>
     <br>
    [mla_gallery]
    attachment_category="{+template:({+request:sub_category+}|{+request:third_category+}|no-term-selected)+}" tax_include_children=false
    posts_per_page=25 mla_output="paginate_links,prev_next" orderby=date order=DESC
    mla_link_href="{+new_url+}?mla_paginate_current={+new_page+}&main_category={+request:main_category+}&sub_category={+request:sub_category,url+}"
    [/mla_gallery]
     
    [mla_gallery attachment_category="{+template:({+request:sub_category+}|{+request:third_category+}|no-term-selected)+}" tax_include_children=false posts_per_page=25 orderby=date order=DESC mla_caption="{+title+} : {+description+}" mla_link_href="/modulo-richiesta-foto/?current_id={+attachment_ID+}" mla_nolink_text=" "]

    It works fine for me. I have just a little problem with a blank row that appears in the table before the third control – perhaps you know why 🙂
    I have, however, a bigger problem with this page I made to request my photos… it does not work with my plug-in TranslatePress (I pay for a pro-version!)… Now I hav disabled it for this page and I added an English translation in the html 🙁
    If I enable the plugin of translation for the page, everything works fine until showing thumbnails (in fact with this plugin, when you change language, the URL of the page changes in /lang/translated-url/ )
    If you can help me (again!!) I can open a new post with a duplicated page in which the plugin of translation is enabled, so you can see the problem…
    Tell me if it is possible…
    Have a nice weekend and thank you so much!!

    • This reply was modified 2 years, 4 months ago by cristiano771.
    • This reply was modified 2 years, 4 months ago by cristiano771.
    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with the good news on your progress. You wrote “ I have just a little problem with a blank row that appears in the table before the third control – perhaps you know why“?

    The “blank row” is a result of having two [mla_term_list] shortcodes to display the second level terms, one of which is empty depending on the first level term selected. The current MLA version suppresses the control but still generates an inline “style sheet” for it. I believe this is causing the blank space. I will investigate a change to suppress the styles and see if that helps.

    Regarding TranslatePress, I found this free version in the Repository:

    Translate Multilingual sites – TranslatePress
    By Cozmoslabs, Razvan Mocanu, Madalin Ungureanu, Cristophor Hurduban

    Is that the right plugin? If so, I will try to help you solve your issue if you open a new support topic in this forum.

    Plugin Author David Lingren

    (@dglingren)

    I did some testing and discovered that the extra inline “style sheet” is harmless; not the problem. The blank row occurs because each of your [mla+term+list] shortcodes is on a separate line. This adds a <br> tag to the page even if the shortcode doesn’t generate any output. To remove the blank row, simply put all of your shortcodes on one line, without line breaks between them. This produces two or three dropdown controls with no vertical space between them.

    If you want to add some space (which looks better), you can define a custom markup template and add the <br /> tag there. This only adds the tag when the control is displayed and results in a nicely spaced layout. To create the custom template:

    1. Navigate to the Settings/Media Library Assistant Shortcodes tab.
    2. Enter “default” in the Search Templates text box and click “Search Templates”.
    3. Click the “Term List” view link above the template table.
    4. Find the “term-list-dropdown (default)” Markup template for the Term List shortcode.
    5. Hover over the template name and click “Copy”.
    6. Give your template a suitable name, e.g., “term-list-dropdown-br”
    7. Update the Description, e.g., “This template adds a <br> tag to the end of the control.”
    8. Scroll down to the “Close” section.
    9. Add a <br /> tag below the </[+itemtag+]> tag.
    10. Add an empty line to the end of the section.
    11. Scroll to the bottom of the page and click “Update” to save the template.

    Once that’s done you can add a mla_markup=term-list-dropdown-br parameter to all four [mla_term_list] shortcodes. I hope that gives you the results you seek.

    Thread Starter cristiano771

    (@cristiano771)

    Thank you so much, David!
    I have removed any <br> tag and I have put the last two dropdown menu on the same line in the shortcode. Now it is just as I was looking for! Thank you again!!

    I am going to open a new post for the issue with TranslatePress… I hope all these requests are not too many :)))

    Cristiano

    Thread Starter cristiano771

    (@cristiano771)

    Dear David, just a little update to the discussion. I have seen that we have a problem with pagination when the user select “UCCELLI” (You can verify by yourself here). The links of pagination do not work properly… Which could be the solution?

    Thank you again,
    Cristiano.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for catching and reporting this problem with the solution I outlined. I neglected to update the mla_link_href= parameter in the pagination controls shortcode to account for the new third-level term list. Here is the corrected parameter value:

    mla_link_href="{+new_url+}?mla_paginate_current={+new_page+}&amp;main_category={+request:main_category+}&amp;{+template:(sub_category={+request:sub_category,url+}|third_category={+request:third_category,url+})+}"
    

    You can see the template that selects either the second- or third-level term value depending on which is present in the request. Let me know if you have problems or further questions regarding this correction; thanks.

    Thread Starter cristiano771

    (@cristiano771)

    Thank you, David! I have update the paginate control:

    <form id="mla-text-form" action="/richiesta-foto/" method="post" class="row">
    <table>
    <tbody>
    <tr>
    <td width="25%" valign="top">Categoria / Specie: </td>
    <td width="50%">
    [mla_term_list taxonomy=attachment_category mla_output=dropdown child_of="400" mla_control_name=main_category  depth=1 mla_item_parameter=current_main_category show_count=false use_filters=true]
    [mla_term_list taxonomy=attachment_category mla_output=dropdown include_tree=127 child_of="{+template:({+request:main_category+}|1)+}" mla_control_name=include_category mla_item_parameter=current_include_category show_count=false pad_counts=false hierarchical=true depth=1 use_filters=true]
    [mla_term_list taxonomy=attachment_category mla_output=dropdown mla_option_value="{+slug+}" exclude_tree=127 child_of="{+template:({+request:main_category+}|1)+}" mla_control_name=sub_category mla_item_parameter=current_sub_category show_count=false pad_counts=false hierarchical=true depth=0 use_filters=true][mla_term_list taxonomy=attachment_category mla_output=dropdown mla_option_value="{+slug+}" include_tree=127 child_of="{+template:({+request:include_category+}|1)+}" mla_control_name=third_category mla_item_parameter=current_third_category show_count=false pad_counts=false hierarchical=true depth=0 use_filters=true]</td>
    <td width="25%" valign="top">
    <input id="text-form-submit" name="text_form_submit" type="submit" value="SELEZIONA">
    </td>
    </tr>
    </tbody></table>
    </form>
     <br>
    [mla_gallery]
    attachment_category="{+template:({+request:sub_category+}|{+request:third_category+}|no-term-selected)+}" tax_include_children=false
    posts_per_page=25 mla_output="paginate_links,prev_next" orderby=date order=DESC
    mla_link_href="{+new_url+}?mla_paginate_current={+new_page+}&main_category={+request:main_category+}&{+template:(sub_category={+request:sub_category,url+}|third_category={+request:third_category,url+})+}"
    [/mla_gallery]
     
    [mla_gallery columns=0 mla_style="responsive" size="thumbnail" attachment_category="{+template:({+request:sub_category+}|{+request:third_category+}|no-term-selected)+}" tax_include_children=false posts_per_page=25 orderby=date order=DESC mla_caption="{+title+} : {+description+}" mla_link_href="/modulo-richiesta-foto/?current_id={+attachment_ID+}" mla_nolink_text=" "]

    But it does not work… I see the third_category passed in the URL of the page, but no thumbs…

    Plugin Author David Lingren

    (@dglingren)

    My apologies. I failed to test out all the combinations of the four [mla_term_list] control values and the parameter change I posted above is incorrect. I regret the inconvenience this caused you. Please give this new parameter version a try:

    mla_link_href="{+new_url+}?mla_paginate_current={+new_page+}&amp;main_category={+request:main_category+}{+template:(&amp;include_category={+request:include_category,url+})+}{+template:(&amp;sub_category={+request:sub_category,url+})+}{+template:(&amp;third_category={+request:third_category,url+})+}"
    

    You can see the updated templates that select any or all of the four term values depending on which are present in the request. Let me know if you have problems or further questions regarding this correction; thanks.

    Thread Starter cristiano771

    (@cristiano771)

    Thanks David, God forbid you have to apologize … I overwhelmed you with requests! Now it works perfectly … I’ll just have to delve into how to change the look of the pagination, but I shouldn’t have any problems.
    Thanks again!

    Plugin Author David Lingren

    (@dglingren)

    I have released MLA version 2.99, which contains the fixes developed for this topic.

    I am marking the topic resolved, but please update it if you have any problems or further questions regarding the fixes described above. Thanks again for working with me on this interesting MLA application.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘MLA_term_list pass value for child_of’ is closed to new replies.