Support » Plugin: Media Library Assistant » Add searc box to Gallery

  • Resolved Zepzilia

    (@zepzilia)


    This may come as an stupid question, but I am a WP newbie.

    I got this photo archive with over 600 images. I want to add a page in my blog where people can come in and search for the terms of their interest in a search box (i.e. cars, ambulances, trucks). I see there is the [mla_gallery] shortcode but I cannot find a field where I can add what I need. could you tell me where is it?

    Thanks in advance.

    https://wordpress.org/plugins/media-library-assistant/

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

    (@dglingren)

    Thanks for your question. There are no stupid questions, and this one has come up a few times before.

    I believe you will find an answer in this recent topic:

    Searchable media archive

    If you paste “my current version of the code” into a normal WordPress page you should get what you want.

    I am marking this topic resolved, but please update it if you need more specific help or if you have problems/questions regarding the suggested solution. Thanks for your interest in the plugin.

    Thanks for your quick response, David.

    I have been reading and studying the links and topics related to term search and so on. I copied the code you offered in another topic and look out nicely –but the search didn’t work 🙁

    I have uploaded circa 20 images and added Att. Tags and Att. Category to all of them. But when I use the search box, it displays nothing, or just one or two images –when clearly there are more of them which have that Att. Tag or Category. I.E. I have a Att. Tag and Att. Category called “ambulance” which I have added to at least six or seven images, but the search box only displays one. I have another term called “planes” , but the search returns nothing.

    I also used the [mla_tagcloud] just to see how it was working and the terms displayed are the default WP tags I created a long time ago. Is there a way to make the [mla_tagcloud] display only Att. Tags and Att. Categories.?

    I’ll keep on trying to figure out how to do it but I would appreciate your advising a lot. This is the link to the website : http://www.enriquemetinides.com/demoblog/archive/

    Plugin Author David Lingren

    (@dglingren)

    Thank you for your update with the additional information. Thank you as well for posting the link to your site, which is very helpful.

    I regret that I did not completely understand your first post and did not give you an accurate answer. The “search form” example uses the built-in WordPress keyword search support, which looks for a match in the Title and Description fields of your Media Library items. It does not look for a match in the Att. Category or Att. Tag terms. I am working on a feature that will support that in a future MLA version, but it does not exist in the current version.

    The best way to accomplish your goal with the current MLA version is, as you suspected, the [mla_tag_cloud] shortcode. Here is an earlier support topic on that subject:

    Using tag cloud shortcode to display galleries

    Briefly, the solution is to create a page with the [mla_tag_cloud] and an [mla_gallery] shortcode to display the matching items. Here is a simple example of that approach:

    <h3>The Tag Cloud</h3>
    [mla_tag_cloud taxonomy=attachment_category number=0 mla_link_href="{+page_url+}?term_slug={+slug+}"]
    
    <h3>The Gallery</h3>
    [mla_gallery post_mime_type=all post_parent=all attachment_category="{+template:({+request:term_slug+}|a-bad-term)+}" mla_nolink_text="No pages to show." posts_per_page=2 mla_output="paginate_links,prev_next" mla_link_href="{+page_url+}?term_slug={+request:term_slug+}"]
    
    [mla_gallery post_mime_type=all post_parent=all attachment_category="{+template:({+request:term_slug+}|a-bad-term)+}" mla_nolink_text="Click a term to display the gallery." posts_per_page=2]

    In this example, the “Tag Cloud” is displaying terms from the Att. Categories taxonomy. You can display Att. Tag terms (taxonomy=attachment_tag) or both (taxonomy="attachment_category,attachment_tag").

    In the [mla_gallery] shortcode a template is used to display nothing until a term is selected:

    • The template: prefix says that this is a Content Template
    • The parentheses “()” around the two elements are used to group them into a list of alternatives
    • The vertical bar “|” between the two elements means “stop when you get a non-empty alternative
    • {+request:term_slug+} will be empty unless there is a term_slug in the URL
    • a-bad-term is a literal value (and thus never empty) which does not match any term in the attachment_category taxonomy, so the gallery will be empty if this alternative is used.

    You can read all about it in the “Content Templates” section of the Settings/Media Library Assistant Documentation tab, but the example should work as-is. You can change the posts_per_page=2 parameter to something more reasonable, e.g., posts_per_page=20. Remember to change it in both shortcodes if you do.

    I hope you find the tag cloud a reasonable solution for your application. I am marking this topic “unresolved” while I work on the “terms search” feature, and I will update it with my progress. If you have any problems or questions regarding the tag cloud alternative, post them here. Thanks for your patience.

    Plugin Author David Lingren

    (@dglingren)

    I have completed development of an enhanced “Keyword(s) Search” and a new “Term Keyword(s) Search” capability for the [mla_gallery] shortcode. You can use either one to let users search by entering all of part of the Title for terms in your Att. Category and Att. Tag taxonomies.

    If you want to try it out you can download and install the MLA Development Version from the “Developers” tab here in the repository. If you do, please let me know how it works for you.

    Here is the source text for two pages you can use to test the new feature. There is a lot of HTML and parameter passing in the examples, but they are not really complicated. Each example has a form to enter keywords and parameters and a paginated [mla_gallery] to show the results.

    Enhanced Keyword(s) Example

    <h3>The Search Form</h3>
    <form id="mla-search-form" action="." method="post">
    <input id="mla-search-box" name="search-string" type="text" value="" />&nbsp;<input id="submit" name="submit" type="submit" value="GO" />
    <input name="mla_search_connector" type="radio" checked="checked" value="AND">and&nbsp;<input name="mla_search_connector" type="radio" value="OR">or
    <input name="mla_search_fields[]" id="search-title" type="checkbox" checked="checked" value="title">Title&nbsp;<input name="mla_search_fields[]" id="search-name" type="checkbox" value="name">Name&nbsp;<input name="mla_search_fields[]" id="search-excerpt" type="checkbox" value="excerpt">Caption&nbsp;<input name="mla_search_fields[]" id="search-content" type="checkbox" checked="checked" value="content">Description&nbsp;<input name="mla_search_fields[]" id="terms-search" type="checkbox" value="terms">Terms
    <input name="sentence" id="search-sentence" type="checkbox" value="true">sentence&nbsp;<input name="exact" id="search-name" type="checkbox" value="true">exact
    <input name="debug" id="search-debug" type="checkbox" value="true">debug
    </form>
    
    <h3>The Search String Gallery</h3>
    
    [mla_gallery post_mime_type=all mla_search_connector="{+request:mla_search_connector+}" mla_search_fields="{+request:mla_search_fields+}" sentence="{+request:sentence+}" exact="{+request:exact+}" s="{+template:({+request:search-string+}|a-bad-term)+}" mla_nolink_text="No pages to show." posts_per_page=2 mla_output="paginate_links,prev_next" mla_link_href="{+page_url+}?search-string={+request:search-string+}&mla_search_fields={+request:mla_search_fields+}&mla_search_connector={+request:mla_search_connector+}&sentence={+request:sentence+}&exact={+request:exact+}"]
    
    [mla_gallery mla_debug="{+request:debug+}" post_mime_type=all mla_search_connector="{+request:mla_search_connector+}" mla_search_fields="{+request:mla_search_fields+}" sentence="{+request:sentence+}" exact="{+request:exact+}" s="{+template:({+request:search-string+}|a-bad-term)+}" mla_nolink_text="Enter a search value above to display gallery." posts_per_page=2]

    Term Keyword(s) Search Example

    <h3>The Terms Search Form</h3>
    <form id="mla-search-form" action="." method="post">
    <input name="mla_terms_phrases" id="mla-terms-phrases" type="text" value="">&nbsp;<input name="mla_terms_search" class="button" id="mla-terms-search-submit" type="submit" value="Search">
    <input name="mla_phrase_connector" id="mla-terms-search-radio-phrases-and" type="radio" checked="checked" value="AND">All phrases&nbsp;<input name="mla_phrase_connector" id="mla-terms-search-radio-phrases-or" type="radio" value="OR">Any phrase
    <input name="mla_term_connector" id="mla-terms-search-radio-terms-and" type="radio" value="AND">All terms&nbsp;<input name="mla_term_connector" id="mla-terms-search-radio-terms-or" type="radio" checked="checked" value="OR">Any term
    <input name="mla_terms_taxonomies[]" type="checkbox" value="category">&nbsp;Categories
    <input name="mla_terms_taxonomies[]" type="checkbox" value="post_tag">&nbsp;Tags
    <input name="mla_terms_taxonomies[]" type="checkbox" checked="checked" value="attachment_category">&nbsp;Att. Categories
    <input name="mla_terms_taxonomies[]" type="checkbox" checked="checked" value="attachment_tag">&nbsp;Att. Tags
    <input name="mla_debug" id="search-debug" type="checkbox" value="true">debug
    </form>
    <h3>The Terms Search Gallery</h3>
    [mla_gallery post_mime_type=all mla_terms_phrases="{+template:({+request:mla_terms_phrases+}|a-bad-term)+}" mla_phrase_connector="{+request:mla_phrase_connector+}" mla_term_connector="{+request:mla_term_connector+}" mla_terms_taxonomies="{+request:mla_terms_taxonomies+}" mla_nolink_text="No pages to show." posts_per_page=2 mla_output="paginate_links,prev_next" mla_link_href="{+page_url+}?mla_terms_phrases={+request:mla_terms_phrases,url+}&mla_phrase_connector={+request:mla_phrase_connector,url+}&mla_term_connector={+request:mla_term_connector,url+}&mla_terms_taxonomies={+request:mla_terms_taxonomies,url+}"]
    
    [mla_gallery mla_debug="{+request:mla_debug+}" post_mime_type=all mla_terms_phrases="{+template:({+request:mla_terms_phrases+}|a-bad-term)+}" mla_phrase_connector="{+request:mla_phrase_connector+}" mla_term_connector="{+request:mla_term_connector+}" mla_terms_taxonomies="{+request:mla_terms_taxonomies+}" mla_nolink_text="Enter a search value above to display gallery." posts_per_page=2]

    I’m testing with this new functionality and it’s working, but I was hoping I could add a dropdown list of all categories to the search form. The ‘tag cloud’ doesn’t really help, because it doesn’t display a hierarchical structure.
    To explain: I have a list of brand names under which are subcategories with all the same titles: brochures, instruction manuals, etc. and .pdf documents are attached to those categories.
    In the backend there is a nice dropdown to choose the category for a media file. I would like to have the same dropdown on the frontend. Is this possible?

    Plugin Author David Lingren

    (@dglingren)

    Thank you for your update; I am happy to hear that the new keyword/term search functions are working for you.

    In the current MLA version (and the Development Version) there is no shortcode or [mla_tag_cloud] parameter that will generate a dropdown or other control that represents the hierarchy for a taxonomy such as Categories or Att. Categories. I did some preliminary work on one, but the WordPress developers are working on some enhancements that will significantly change the way these functions are handled and I am waiting to see what they do.

    In the interim, I would be happy to work with you on a custom solution for your application. Here is an earlier topic along similar lines:

    Show main category with list inside

    That solution uses the “Collapse-O-Matic” plugin, but you could so something similar with a dropdown control. The basic idea of creating WordPress templates can be adapted in many ways.

    Another, somewhat simpler approach would be to develop a small custom plugin that implements a shortcode you can use to generate the control. Would that be a good solution for your application?

    If you would like to proceed, give me your contact information so I can send you a test version of the custom plugin. When we’re finished I will post the results here for everyone to see. You can use the Contact Us page at our web site:

    Fair Trade Judaica/Contact Us

    Thanks for an interesting question. I look forward to working with you on a solution that fits your application.

    Thank you for your extended reply David. Digging further into your plugin and it’s a wonderful piece of work!

    I now ended up using the ‘tosca30-dropdown’ from the examples in your plugin and described here: How to display pad_counts for hierarchical taxonomies. The only problem I encountered was that it returned category pages for the “attachment_category” taxonomy, which will not display any media. So I did a ‘rough hack’ like this: str_replace('attachment_category/', 'library/?term_slug=' I’m sure there’s a better way, but I’m only a php amateur.

    Anyway, the menu works fine, but now I would like to combine it with a search and that doesn’t work. My shortcode is like this: [mla_gallery post_mime_type=application/pdf post_parent=library s="{+template:({+request:search-string+}|a-bad-term)+}" mla_nolink_text="Click on the links in the menu on the right or enter a keyword below to find a manual." posts_per_page=10 size=icon orderby=name order=asc attachment_category="{+request:term_slug+}"]

    I thought that would work as either of the variables (s= or attachment_category=) would be empty, or am I wrong? But only the keyword search works, not the clicking on menu links. Those work if I do two separate shortcodes but then I end up with double results. I hope you know how I can combine this.

    Thanks for your support.

    Hello David,

    I am glad this topic has helped someone else with his own doubts. As for me, I started by adding “keywords” to the caption field on every image, and used the code you provided on your second reply to me, which I think has worked out fine on my website. Now the users can search for terms in the box or click on the tag cloud.

    I am creating the the Spanish version of the website, with Spanish terms, in another WP directory but in the same domain. I copy/pasted the same code I used on the English version. However, when I search something on the box and click the “Go” button, it redirects me to the website’s home page -no results are shown, and if I click on any tag from the tag_cloud, nothing happens. Could it be that a sort of “interference” is generated by having two WP installs on the same domain?

    http://www.enriquemetinides.com/esp/?page_id=15

    Thanks for your support!

    Plugin Author David Lingren

    (@dglingren)

    Thank you, @zepzilia, for gracefully prompting me to realize that two different people have posted to this topic.

    @frizzie55, it would be very helpful if you opened a separate support topic for your questions about the tosca30-dropdown and combining it with a keyword search. I am easily confused by working with two people from one topic. Would that be possible?

    Plugin Author David Lingren

    (@dglingren)

    So, @zepzilia, let’s proceed to your question about the Spanish version of your site. I am not quite sure what you mean by “the Spanish version of the website, with Spanish terms, in another WP directory but in the same domain“. Do you really mean two copies of the software, with separate wp-config.php files and so forth? If so, it sounds risky.

    I have installed separate WordPress sites in different subdomains without any trouble, e.g., esp.enriquementindes.com or something similar. However, if you want a multi-language site you should investigate WordPress plugins like WPML and Polylang. I have made both of these work well with MLA.

    In any case, I can give you some hints about the “interference” you are seeing. Both of the symptoms you are having are related to the use of arguments like ?page_id=15 to navigate the site.

    First, the “GO” button issue. The HTML for your search form looks like this:

    <form id="mla-search-form" action="." method="post"><input name="search-string" id="mla-search-box" type="text" value=""><br>
    <input name="submit" id="submit" type="submit" value="GO"></form>

    The action="." parameter links back to the current page when the “GO” button is clicked, but it only uses the href portion of the URL to do so. In this case, the href portion of the URL is http://www.enriquemetinides.com/esp/, and you are using a query argument, ?page_id=15 to get to the right WordPress page. The query argument is not part of the “.” so you get the home page.

    You can try changing the action parameter to the explicit, complete URL as follows:

    action="http://www.enriquemetinides.com/esp/?page_id=15"

    That will work for the specific WordPress page you have placed the form on.

    Second, the term cloud issue. This is a similar problem; here is one of your term links:

    http://www.enriquemetinides.com/esp/?page_id=15?term_slug=1940

    You can see that the ?page_id=15 query argument is followed by ?term_slug=1940, and the second “?” is invalid HTML. If you can find the ?term_slug= parameter and change it to &term_slug= you should have a better result.

    The above suggestions will fix your immediate issues, but I have serious doubts about your overall strategy (as I understand it). If you want a site that will work gracefully in two or more languages you would be well served by learning and using one of the “multi-lingual” plugin solutions for WordPress.

    Thank you for your detailed answer, David.

    By the time I was building the website I had no idea of the troubles you are now talking of. I first created the “/demoblog” subdomain in English and latter, the “/esp” subdomain on Spanish. This is my first WP site so I may have made many mistakes, I don’t know if they can be corrected on short time…or by far, how they are generated and why. I will try to investigate the Plugins you are suggesting me 🙁

    I made the changes you suggested, and now when I use the search box, yes, the images show up, but not many of them and if I want to go to the “next” page, nothing is displayed. As for the tag_cloud, it works now, but with the same problem: page 2, 3, and so forth are not displayed. I am sure it has something to do with the &term_slug= thing but I do not know if I should go to a .php file or something to configure it.

    This problem is exclusive of the Spanish part, which is the second I created. The English one works so good and smooth and gives no trouble. So I am sure it has to do with something I did wrong.

    Plugin Author David Lingren

    (@dglingren)

    I had a look at your /esp/ page and I can see the problem you report. It is, as you suspect, the encoding of the term_slug argument in the URL. For example, the third page URL contains these arguments:

    ?page_id=15%3Fterm_slug%3Dblanco-y-negro&mla_paginate_current=3

    but it should look like this:

    ?page_id=15&term_slug=blanco-y-negro&mla_paginate_current=3

    There are two problems. First, you have somehow encoded the punctuation before and inside the term_slug argument; %3F and %3D are interpreted as data characters, not delimiters. Second, %3F is the code for the question mark, not the ampersand ( that would be %38).

    You need to find whatever code is generating %3Fterm_slug%3D and change it to generate &term_slug=.

    If the code is in a WordPress Post or Page, make sure you are using the “Text” tab of the editor, not the “Visual” tab.

    I hope that solved your immediate problem. Let me know what you find.

    The code is in a WP Page.

    I put together both code versions and found out both where equal except by one part, which is the following:

    In the English site:

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

    On the Spanish page:

    [mla_tag_cloud taxonomy=attachment_category number=0 mla_link_href="{+page_url+}&term_slug={+slug+}"]

    As you can see the & thing is there but when I replace it for the?term_slug={+slug+}, no images are shown. So I left it the way it was.

    I was wondering, is there a way to tell it to show ALL the search results in one page?

    Plugin Author David Lingren

    (@dglingren)

    Thanks for posting the source of your [mla_tag_cloud] shortcodes. They look fine, and I now realize that my earlier post was not very clear.

    The problem is not related to the [mla_tag_cloud] shortcodes. You must have another [mla_gallery] shortcode on the page that is generating the pagination links (for example, “1 2 3 … 58 Next »“) that appear below the cloud. It is the syntax in these pagination links that is failing.

    Can you have a close look at the pagination shortcode and make sure it is correct? If it looks good to you, please post it here so I can try the same thing on my test site.

    Well, I compared this to the other version, the english site and it is the same.

    First we have te code referring to the search form:

    [mla_gallery post_mime_type=all post_parent=all s="{+template:({+request:search-string+}|a-bad-term)+}" mla_nolink_text="No pages to show." posts_per_page=2 mla_output="paginate_links,prev_next" mla_link_href="{+page_url+}?search-string={+request:search-string+}"]
    
    [mla_gallery post_mime_type=all post_parent=all s="{+template:({+request:search-string+}|a-bad-term)+}" mla_nolink_text="Ingrese uno o varios términos para desplegar la galería" posts_per_page=40]

    Later the code referring to the tag_cloud

    [mla_gallery post_mime_type=all post_parent=all attachment_category="{+template:({+request:term_slug+}|a-bad-term)+}" mla_nolink_text="No pages to show." posts_per_page=2 mla_output="paginate_links,prev_next" mla_link_href="{+page_url+}?term_slug={+request:term_slug+}"]
    
    [mla_gallery post_mime_type=all post_parent=all attachment_category="{+template:({+request:term_slug+}|a-bad-term)+}" mla_nolink_text="Haz click en el término que te interesa" posts_per_page=40]

    So in general the thing looks like this:

    [mla_gallery post_mime_type=all post_parent=all s=”{+template:({+request:search-string+}|a-bad-term)+}” mla_nolink_text=”No pages to show.” posts_per_page=2 mla_output=”paginate_links,prev_next” mla_link_href=”{+page_url+}?search-string={+request:search-string+}”]

    [mla_gallery post_mime_type=all post_parent=all s=”{+template:({+request:search-string+}|a-bad-term)+}” mla_nolink_text=”Ingrese uno o varios términos para desplegar la galería” posts_per_page=40]

     
    <h3>Nube de etiquetas</h3>
    [mla_tag_cloud taxonomy=attachment_category number=0 mla_link_href=”{+page_url+}&term_slug={+slug+}”]
    <h3>Galería</h3>
    [mla_gallery post_mime_type=all post_parent=all attachment_category=”{+template:({+request:term_slug+}|a-bad-term)+}” mla_nolink_text=”No pages to show.” posts_per_page=2 mla_output=”paginate_links,prev_next” mla_link_href=”{+page_url+}?term_slug={+request:term_slug+}”]

    [mla_gallery post_mime_type=all post_parent=all attachment_category=”{+template:({+request:term_slug+}|a-bad-term)+}” mla_nolink_text=”Haz click en el término que te interesa” posts_per_page=40]

    Sorry for causing so much trouble!

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Add searc box to Gallery’ is closed to new replies.