Gallery layout with thumbnails
-
Hi,
First of all thanks a lot for this wonderful plugin!
I have followed the below tutorial to add a searchbar for my photos, which works with rtmedia :
http://community.rtcamp.com/t/search-feature/2992/2I would like, when we make a search, that the resulting thumbnails photos display like in my rtmedia gallery (that they follow the html from rtmedia gallery) and not the by default layout from mla.
I don’t know which file to modify to do that.Thank you very much,
Marine
-
Thank you for your kind words and for your question. Thanks as well for posting the link to the topic you found in the rtMedia Community forum. That topic is a couple of years old and things have improved since it was written. In particular, the “MLA BuddyPress & rtMedia Example” example plugin has been enhanced to work with the
[rtmedia_gallery]shortcode so you can use MLA to select your items and use[rtmedia_gallery]to format them for display. This update has not yet been added to the current MLA version, but I will give you instructions for getting it below.The updated example plugin adds a custom “rtmedia=gallery” parameter that filters the items returned by the
[mla_gallery]query and uses[rtmedia_gallery]to display the items that have an rtMedia ID. All you have to do is add this parameter to your [mla_gallery]shortcode and you should get the results you need.You do not say of you are using the free version of rtMedia or if you have purchased the rtMedia Pro collection of add-ons. If, for example, you are using the “rtMedia Sorting” add-on you will need an update to that plugin to make it work with MLA. Let me know if that’s true for your application.
To get the updated example plugin you will have to download and install the latest MLA Development Version To get the Development Version, follow the instructions in this earlier topic:
Shortcode not working in (special) widget
Once the Development Version is installed, navigate to the Settings/Media library Assistant Documentation tab and click the “Example Plugins” button. Type “rtmedia” in the text box and click “Search Plugins” to filter the table.
You are looking for “MLA BuddyPress & rtMedia Example” plugin. Find that plugin and hover over the title in the left-most column. Click the “Update” (or “Install”) rollover action, then go to the WordPress Plugins/Installed Plugins submenu and activate the new plugin as you would any other WordPress plugin. If the old plugin is still there, deactivate it.
Finally, go back to your search page and add the
rtmedia=galleryparameter to your[mla_gallery]shortcode.It would be great if you can install the Development Version and updated example plugin and let me know if they work for you. If you have any problems or further questions, post an update here and I will give you more specific help. It would be very helpful if you can post the complete source text of your search page so I can see exactly the form and shortcodes you are using.
Thank you so much David, it works very well now with the development version and the updated example plugin !
Here is the code added to the search page :
<form id="photo-search-form" action="." method="post"> <input size=50 id="mla-search-box" name="search-string" type="text" value="" placeholder="Enter your search words here...." autofocus/><input id="submit" name="submit" type="submit" value="Search" /> </form> <hr> <?php echo do_shortcode('[mla_gallery rtmedia=gallery post_parent=all posts_per_page=100 s="{+template:({+request:search-string+}|a-bad-term)+}" buddypress_urls="link" mla_nolink_text="Enter search terms above and hit Search!" mla_caption="{+author+} - <strong>{+title+}</strong>" mla_output="paginate_links,prev_next" mla_link_href="{+page_url+}?search-string={+request:search-string+}]');I have another question: is it possible to search images also by a custom field ?
Actually, I have created a field called
$cityin the rtmedia uploader, and after the image upload, this city, writen by the user, is displayed near the description area in the image lightbox.(I did it with the following code :
https://gist.github.com/mangesh/66116130398b8a136458cbf7cc3d736b )I would like that when we write a city name in the MLA search box, it could display the images containing that city.
Thank you very much
Thanks for the good news regarding your progress and for posting the source text of your search page. I am a bit puzzled by the “echo do_shortcode” text; it looks like you put this code in a template file, not in the WordPress page content. Is that right? On my system this shortcode works fine in the page content:
[mla_gallery rtmedia=gallery post_parent=all posts_per_page=100 s="{+template:({+request:search-string+}|a-bad-term)+}" buddypress_urls=link mla_nolink_text="Enter search terms above and hit Search!"]I removed the
mla_caption,mla_outputandmla_link_hrefparameters because they are ignored when the gallery display is handled by[rtmedia_gallery].You wrote “I would like that when we write a city name in the MLA search box, it could display the images containing that city.” That is a surprisingly complicated requirement!
The current “keyword search” feature of
[mla_gallery]allows you to search several text fields in thewp_postsdatabase table. MLA optionally extends this search to taxonomy terms if you add “terms” to themla_search_fieldsparameter. All of this requires some custom SQL coding that modifies the WordPress WP_Query logic.Keyword search also accepts multiple words/phrases and lets you specify what happens when more than one word/phrase is entered. For example, if you enter “paris cat” the default requires that both of these words must be present. If you code
mla_search_connector=ORyou get all items where “paris” is present added to all items where “cat” is present.Finally, case-insensitive and partial word matches are allowed. If you enter “par” you will match items containing “Paris”, “paris” and “party”.
WordPress allows you to search on custom field content but does not support multiple values in one search.
Finally, if you enter a mix of city names and search words in a single field there is no way to separate out which is which. I suggest you add a separate City field to you search form for this search.
I did some experimenting and came up with a combination that mostly works. You can enter this text in a test page of your own and play with it:
<form id="photo-search-form" action="." method="post"> Keywords: <input size=50 id="mla-search-box" name="search-string" type="text" value="" placeholder="Enter your search words here...." autofocus/><br> City: <input size=50 id="mla-search-city" name="city-string" type="text" value="" placeholder="Enter your city here...."/><br> <input id="submit" name="submit" type="submit" value="Search" /> </form> <hr> [mla_gallery rtmedia=gallery post_parent=all posts_per_page=100 s="{+template:({+request:search-string+})+}" meta_key=City meta_value="{+template:({+request:city-string+})+}" meta_compare=LIKE buddypress_urls=link mla_nolink_text="Enter search terms above and hit Search!"] <hr>There are two shortcomings with the above solution:
- Even if you do not enter a city value, only items with SOME value in the “City” custom field are selected.
- All of items with some value in the “City” custom field are selected/displayed when both of the text boxes are empty.
Both of these could be fixed with a bit of PHP code that handles the shortcode parameters in a different way. If the separate search fields solution would work for you I can work out the PHP code required to clean it up. Let me know what you think.
Hi,
Thanks a lot for all your help.
Yes, I added “echo do_shortcode” because I used to put the code in the model template file of the page.I copied the code that adds a separate city field from the searchbox (directly in the page).
The searchbox works fine (but it displays results only when the city box is empty) but the city box doesn’t work, it doesn’t find anything.I have seen in my SQL database that my ‘city’ meta-key is located in the ‘wp_rt_rtm_media_meta’ table. Perhaps that it is linked to my problem…?
Thanks again,
MarineThanks for clarifying your “city” field and where it’s stored. Please accept my apologies for not reading the “Add custom field in activity page and display the value submitted in the custom field in lightbox” topic you posted a link to more carefully.
You are right; the “city” field you implemented is stored and managed by rtMedia, not WordPress. My earlier post applies to WordPress custom fields, or “post metadata”. The solution I outlined in the earlier post will not help you.
Since your city field is managed by rtMedia using their own SQL queries, any solution for adding it to the search form would also involve custom queries using PHP code and raw SQL. It might be feasible to implement a stand-alone “city” search, but I do not see any straightforward way to combine the city search with the MLA/WordPress keyword search. I regret the news is not better, but if a stand-alone search would help I can give you more specific guidance on that.
I have been pondering your requirements and it may be possible to create a two-stage query process that would first select items based on keyword(s) and then filter the resulting list of rtMedia items by city. This would be straightforward but would involve two separate queries. It would work fine for tens or hundreds of items coming out of the first query but may not scale to thousands.
Can you tell me more about how large your site will be, i.e., how many images in total and how many might be returned by the keywords query?
Hi David,
Thank you very much for your answer.
I have changed my code so that my ‘city’ meta-key is now stored in my database in ‘wp_postmeta’.
After this change, the code that you wrote with a combination of keyword search and city search works well.
I still have a question :
If I add another meta-key called ‘country’ for example, is it possible to gather all the search bars in only one search bar?I would like that the user can type either a city, a country, or a word contained in the image title or in the description, to display the images which contain these words.
It doesn’t matter to know if the word written is a city or a county or a word from the description, it would be a global search on all these fields.Thank you,
MarineThanks for your update and the good news about your progress. I am happy you could adapt your solution to use the WordPress custom field features.
You asked “… is it possible to gather all the search bars in only one search bar?” It would be possible to perform three (or more) separate database queries and then de-duplicate the results. It might be possible to combine some or all of the queries into a smaller number but I would have to experiment before I gave a good answer. The time and memory required for the queries depends on the number of items in the database, of course.
You wrote “It doesn’t matter to know if the word written is a city or a county or a word from the description, it would be a global search on all these fields.” The normal WordPress WP_Query logic combines parameters with “AND”, i.e. all of the parameters must be satisfied. You want the keywords/city/country queries combined with “OR”, i.e. any one of the parameters can be satisfied. That means some PHP code is required to process the parameters in a different way.
You must also decide how to handle the case where a user enters more than one word in the search bar, e.g., what happens if “Paris London Animal”, or “United Kingdom” is entered. If words are combined with “OR” both of these examples would match an item with “Animal Kingdom” in the Title or Description fields. Is that acceptable?
You might consider implementing at least “country” as a taxonomy with a fixed number of pre-defined choices.
If you think the performance will be acceptable and you can answer the “multiple words” question I can investigate further. I am traveling for a few days so it may take some time to make progress.
I have created a new example plugin that implements a solution for your “one search bar” application. It is part of the latest MLA Development Version dated 120161127. To get the Development Version, follow the instructions in this earlier topic:
Shortcode not working in (special) widget
Once the Development Version is installed, navigate to the Settings/Media library Assistant Documentation tab and click the Example Plugins button. Type multi in the text box and click Search Plugins to filter the table.
You are looking for MLA Multi-search 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 new plugin as you would any other WordPress plugin.
Finally, go back to your search page and add the
multi_searchparameter to your [mla_gallery] shortcode. For example:<form id="photo-search-form" action="." method="post"> Keywords: <input size=50 id="mla-search-box" name="search-string" type="text" value="" placeholder="Enter your search words here...." autofocus/><br> <input id="submit" name="submit" type="submit" value="Search" /> </form> <hr> [mla_gallery rtmedia=gallery posts_per_page=100 s="{+template:({+request:search-string+}|a-bad-search-value)+}" multi_search="keyword:,custom:City,custom:Country" buddypress_urls=link mla_nolink_text="Enter search terms above and hit Search!"] <hr>You will need to change
custom:City,custom:Countryto the names of your two custom fields.It would be great if you can install the Development Version and new example plugin and let me know if they work for you. In particular, experiment with multi-word city/country names.
-
This reply was modified 9 years, 5 months ago by
David Lingren.
I have released MLA version 2.40, which contains the “MLA Multi-search Example” plugin developed for this topic.
I am marking the topic resolved, but please update it if you have problems or further questions regarding the example plugin.
Hi David,
Thank you very much for your answer. I tested the solution, it works if we enter either a city or a country, but it seems that it doesn’t work if we enter both in the searchbar. (Also, with the updated mla version, I usedrtmedia=gallerybut the gallery doesn’t display like rtmedia).I have worked again on my website, but I am facing a big issue. Actually, my custom fields problem seems much more difficult than what I thought.
I use rtmedia uploader to allow people to upload videos and photos, and to add custom fields with their medias. For a video upload for instance, people can add custom fields which are : select dropdowns for ‘city’ and ‘activity’ fields, and an input text for a description.
They can add several lines (thanks to an increment on custom fields). Each line contains a city, an activity, and a description field.For example, a user could add for its video :
(City field) (Activity field) (Description field) Paris Eiffel Tower We visited te eiffel tower and it was nice Versailles Castle The Versailles Castle is situated near Paris Marseille Harbor Dinner in front of Marseille HarborAfter the video upload, these custom fields are then displayed near the video lightbox.
I don’t know if there is a way to handle it in the searchbar.
For instance, if a user enters “Paris”, it would display the media. If it enters ‘Paris and Eiffel Tower’ also, but if it enters ‘Paris’ and ‘Harbor’ the media should not be displayed in the gallery.I would also like to add a menu to the main gallery page, to filter medias by cities and/or activities. It would work the same way as the searchbar.
I am quite lost if I should use taxonomies instead of custom fields ‘city’ and ‘activity’ fields, because there are several cities and several activities for each media, and if my issue is feasible or not.
Thanks again for all your help
Thanks for your update with your progress and additional questions.
You wrote “it doesn’t work if we enter both“. That’s true; if you enter “Paris France” it will search for “Paris France” in the city field and then for “Paris France” in the country field. It has no way of knowing which part of your entry is a city and which part is a country.
You wrote “gallery doesn’t display like rtmedia“. Can you post the entire source text of the shortcode you are using so I can try to reproduce the problem on my system. If you have the MLA BuddyPress & rtMedia Example plugin active it should still work with the new versions.
You wrote:
I use rtmedia uploader to allow people to upload videos and photos, and to add custom fields with their medias. For a video upload for instance, people can add custom fields which are : select dropdowns for ‘city’ and ‘activity’ fields, and an input text for a description.
They can add several lines (thanks to an increment on custom fields). Each line contains a city, an activity, and a description field.Can you tell me exactly how you added these fields? I know how to add rtMedia attributes (which are implemented as WorkPress taxonomies) to the upload form, but not text boxes or repeating fields.
Thanks for any additional details you can provide.
Hello David,
First thank you because you have helped me a lot a few months ago on my website. Since my long delay, I have made modifications to try to make it more simple, and I have new questions.
People can upload media with rtmedia, and I display the global rtmedia gallery using :
[mla_gallery rtmedia=gallery post_parent=all posts_per_page=100 buddypress_urls=link]Do you know if it is possible to display media with a query on their title?
For example, I would like to display only media containing “mainImage” in the title, in the gallery. I don’t know if it is possible by modifying the shortcode, something like that :
[mla_gallery rtmedia=gallery post_parent=all posts_per_page=100 <strong>media_title="mainImage"</strong> buddypress_urls=link]Or if it is not possible with the title in particular, perhaps is it possible to show the gallery of medias containing “mainImage” in their whole post?
Also, I have created a custom post type, called “Description” . Each “Description” post contains text and taxonomies. The title of each “Description” post ($post_title) is a number corresponding to a rtmedia id.
With a MLA searchbar, I would like, when a user writes for example “Paris France” in the search bar, that it searchs all the “Description” posts containing these 2 words ; and that it displays in a gallery the rtmedia medias whose media_id is the title of the description posts.
For instance, if three “Description” posts contain the words “Paris” and “France”, we retrieve their titles ($post_title) : (420, 500 and 600 for example) and then we display a gallery with the medias whose media_id are 420,500 and 600.
Thanks a lot for your time,
Marine
I will reply to your most recent post in the new topic you opened for it:
Display rtmedia gallery with a query on the title or media_id
The topic ‘Gallery layout with thumbnails’ is closed to new replies.