• Resolved jhdean

    (@jhdean)


    Hello David,

    Is it possible with Media Library Assistant to create a shortcode that uses variables and formulas which could be used in a generic page template that when called from a link on any primary image thumbnail in a gallery. would capture the thumbnail image file name or id in a variable and use it as the primary image on the target page, and then, using tag filters and/or terms common to the primary and detail images file names, generate a gallery of related detail images along with their titles, captions and descriptions also on the page? Being able to have a generic page that could be linked to from any image and then be populated through a formula based on the selected image would be a huge time saver and avoid the necessity of creating individual detail pages for every set of images in a portfolio.

    Thanks,
    Jeff

    https://www.ads-software.com/plugins/media-library-assistant/

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

    (@dglingren)

    Thanks for your question, which is along the same lines as this earlier support topic:

    Show tags in attachment page

    There are some simple solutions for passing a single taxonomy and term from a “primary image thumbnail” to build a [mla_gallery] of items having that assignment, but if you really need “tag filters and/or terms common to the primary and detail images” the solution is more complex.

    If you are willing to do a bit of PHP coding, you can adapt some of the MLA examples to get the results you want. Here are some examples that do something similar.

    First, the /media-library-assistant/examples/mla-child-term-hooks-example.php.txt file contains code to build a gallery of “primary image thumbnails”. Here is the WordPress page that uses the hooks:

    This page has a single-image gallery for each child term of a given parent and a complete gallery for a specific term, when selected.
    
    The mla-child-term-hooks-example.php example plugin must be active for this page to work.
    
    <h3>Summary Gallery</h3>
    [mla_gallery my_parent_terms="attachment_category=galleries" my_page="permalink='/gallery-thumbnails/' queryarg=term_slug"]
    
    <h3>Term-specific Gallery</h3>
    [mla_gallery attachment_category="{+template:({+request:term_slug+}|a-bad-term)+}" mla_nolink_text="Click an image above to select a term."]

    The first shortcode uses the hooks to build a [mla_gallery] containing one image assigned to each child term in the “galleries” attachment_category. You may not need this step if you have an alternate way of building your “primary image thumbnail gallery”, but this example shows that you can build a gallery from any kind of logic your application requires.

    The second shortcode is your primary image thumbnail gallery. The links from each item in this second gallery go to the Attachment/Media Page for the image; that’s your “target page”. These target pages are composed by the WordPress Template files attachment.php or image.php, depending on your theme. This part of the exercise is covered in the earlier support topic.

    I have included the Template files and related functions.php in the /media-library-assistant/examples/twentytwelve-mla child theme. The Templates are in image.php, page-single-image.php and content-single-image.php. The mla_custom_terms_list function in the functions.php file generates a clickable list of the terms assigned to the image. You can replace that function call with code to display “a gallery of related detail images along with their titles, captions and descriptions” using do_shortcode. If you want to follow the example trail to the end you can define one more WordPress page, titled “Tag Gallery”:

    You must install and activate the "MLA Child Theme" to support this page.
    
    The page requires query arguments for taxonomy and term, e.g.:
    
    https://mladev/tag-gallery/?my_taxonomy=attachment_category&my_term=new-category
    
    This page is displayed when the user clicks on a taxonomy term at the bottom of the "image.php" page, i.e., the "Singular Page/Single Post Page/Attachment Post" page for the "image" MIME type.
    
    The page is also displayed from the "Single Image" page, driven by the page-single-image.php and content-single-image.php templates. Define "Single Image" (can be empty) and call it with query arguments for item and taxonomy, e.g. "?post_id=1916&taxonomy=attachment_caregory"
    
    The terms list at the bottom of the Attachment Post page is generated by a custom function added to the "image.php" template.

    I know the above trail of files and code is complicated, but it shows what is possible. I am happy to answer more specific questions about the examples or your application and work with you to get a specific solution for your application. I will leave this topic unresolved until I hear back from you. Thanks for your interest in the plugin.

    Thread Starter jhdean

    (@jhdean)

    Thank you for putting the information together David,

    Looks like I have some studying to do. I’ll be in touch as needed once I know more about how it works.

    Jeff

    Thread Starter jhdean

    (@jhdean)

    Hello David,

    After rethinking my strategy, I am wondering if a simpler solution is available.

    Say I have a pre-existing page with a primary image and description on it. I want to have a gallery of related detail images. The common factor is they all will have the same value in the Title field.

    Is there a way in the shortcode to specify the content of the gallery based on whether an image in the media library has the specified title? I can generate the shortcode in advance so I will already know what the title is and can specify it in the shortcode. It won’t have to be determined by the shortcode.

    Thanks,
    Jeff

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your updates and the thought you’ve been putting into solutions for your requirements.

    Your “simpler solution” sounds very promising, and it takes advantage of some recent [mla_gallery] enhancements. The “Keyword(s) Search” section in the Settings/Media Library Assistant Documentation tab contains all the information you need.

    In the current MLA version you can use the s parameter to specify the title you want to match. You can use the mla_search_fields=title parameter to restrict the search to the title field. You can use the exact=true parameter (or the sentence=true parameter) to ensure an accurate match.

    Give the Keyword(s) Search parameters a try and let me know of they work for you. I can help with any problems or further questions you have.

    Thread Starter jhdean

    (@jhdean)

    Hello David,

    Is there a way to search the MLA forum?

    Thanks for the direction. Venturing forth I have made been able to display images with the specified title. I am trying to suppress or replace the default caption displayed below the image.

    [mla_gallery mla_search_fields=title s=”Early Risers” mla_caption=”{+title+}”] displays the title field.

    with: [mla_gallery mla_search_fields=title s=”Early Risers” mla_caption={title}] the word title with square braces is displayed.

    Is there a way to display empty text in place of the caption or only text that is written in the shortcode without the square braces displaying around it?

    Also, by including link=”file”, the images open in the FooBox light box which I have enabled for all images.

    I tried adding mla_rollover_text='{+date+} : {+description+}’ to see how that worked but didn’t get the syntax correct and broke the gallery display. Can you clarify how it would be integrated and how I would use plain text with it as well?

    So far, so good. I see that this is a very capable plugin and look forward to gradually understanding how to use it fully.

    Thanks,
    Jeff

    Thread Starter jhdean

    (@jhdean)

    Hi David,

    Back to your first response:

    “There are some simple solutions for passing a single taxonomy and term from a “primary image thumbnail” to build a [mla_gallery] of items having that assignment,”

    In the following shortcode: [mla_gallery mla_search_fields=title s=”Early Risers” mla_caption=”{+title+}” link=”file”], can I replace the s=”Early Risers”, (Early Risers is the title of the main image on the page), with s= and then a formula that extracts the title from the main image instead of having to hard code it? This shortcode would then be used in the theme’s image target page or in an externally generated page template for each image.

    I tried working with various examples but could not get it to work.

    Thanks again,
    Jeff

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with the progress you’re making.

    Is there a way to search the MLA forum?

    No, sadly. The only search offered is Repository-wide, and for plugin-specific searches it is useless. This is one of my many frustrations with the Repository.

    Is there a way to display empty text in place of the caption or only text that is written in the shortcode without the square braces displaying around it?

    • mla_caption="title" will display the literal “title”.
    • mla_caption="{+description+}" will display the Description, if non-blank, or nothing.
    • mla_caption="{+template:({+description+}|{+caption+}|title+}" (a Content Template) will display display the Description, if non-blank, or then the Caption, if non-blank or finally the literal “title”.

    The “title with square braces” looks like a small MLA defect, which I will fix. It should display “title with curly braces”.

    Thanks for the clarification regarding FooBox; one of the many lightbox plugins I haven’t tried, yet. Are you also using FooGallery?

    I tried adding mla_rollover_text…
    This is a bit subtle; the date and description fields don’t work well in this context, and because the “rollover text” goes in the HTML title attribute some values will cause syntax errors. I suggest this alternative:

    mla_rollover_text='{+post_date,attr+} : {+post_content,attr+}'

    The post_date and post_content Data Sources will work in this context, and the ,attr format option will encode them for use in an HTML attribute. Let me know if that works for you.

    Plugin Author David Lingren

    (@dglingren)

    Just before my last response you wrote:

    “can I replace the s=’Early Risers’, (Early Risers is the title of the main image on the page), with s= and then a formula that extracts the title from the main image instead of having to hard code it?”

    Your question inspired an improvement in the [mla_gallery] (and [mla_tag_cloud]) code, which I have just uploaded to the MLA Development Version here in the Repository. With this enhancement you can access the following post-/page-level fields in data selection parameters:

    'instance' => $instance,
    'selector' => "mla_gallery-{$instance}",
    'site_url' => site_url(),
    'base_url' => $upload_dir['baseurl'],
    'base_dir' => $upload_dir['basedir'],
    'id' => $post->ID,
    'page_ID' => $post->ID,
    'page_author' => $post->post_author,
    'page_date' => $post->post_date,
    'page_content' => $post->post_content,
    'page_title' => $post->post_title,
    'page_excerpt' => $post->post_excerpt,
    'page_status' => $post->post_status,
    'page_name' => $post->post_name,
    'page_modified' => $post->post_modified,
    'page_guid' => $post->guid,
    'page_type' => $post->post_type,
    'page_url' => get_page_link(),

    I haven’t updated the Documentation tab yet, but the code is there. For your specific example, you can replace s="Early Risers" with s="{+page_title+}" to get the generic results you want. You should also consider adding exact=true to your shortcode to prevent false matches.

    If you need help installing the Development Version, let me know.

    Thread Starter jhdean

    (@jhdean)

    Thank you David,

    Sounds like a great addition. I’ll try installing the update and try it out.

    I tried your example from your previous response:
    mla_caption=”{+template:({+description+}|{+caption+}|title+}” showed the description which did exist but began with an error about a missing closing parenthesis. When I removed the first parenthesis after “template:”, the error was gone.

    Is there a parameter for orderby= to sort by the file name of each gallery image?

    Plugin Author David Lingren

    (@dglingren)

    Thanks for finding and fixing the error in my example; my original code had a closing parenthesis after “title”, i.e. mla_caption="{+template:({+description+}|{+caption+}|title)+}". Either fix will work.

    There is no native orderby= parameter that will sort by file name, because the database does not contain exactly that value. The attached_file and the guid database fields usually have the month and year prepended to the name itself.

    If your application requires sorting by the file name you can use the MLA Custom mapping feature to create a custom field from the file_name or name_only Data Source. Once that’s done you can use the custom field in your orderby= parameter; there’s an example of this in the Documentation tab. If you need more specific help, let me know.

    Thread Starter jhdean

    (@jhdean)

    Hi David,

    I installed the development version after deleting the other. I was happy to see that my field and taxonomy mapping settings remained. One odd thing was the MLA zip file ended up in the media library.

    Thanks very much for this addition!
    It has made it possible for me to create a saved layout in the Divi theme I am using which when used to make a new page that is named with an image title, will populate the page with the primary image and it’s description along with a gallery of detail images with the same image title. This greatly reduces the time in generating detail pages for every sculpture I add images for. Make a new page, name it, done!

    I have some questions on fine tuning:

    Sorting a gallery-
    The filenames are for example early_risers-1.jpg through early_risers-5.jpg
    I have created a custom field, image_file_sort_name and put file_name in the EXIF/Template Value field and selected EXIF under Priority, also tried with name_only. When I saved it and tried mapping, no value was filled into the field.

    mla_itemwidth-
    I have been successful using the size=medium or small or full but not mla_itemwidth=”600px”. This is for when a single image meets the filtering criteria with a columns=0 specification.
    [mla_gallery columns=0 mla_search_fields=title s=”{+page_title+}” tag=”primary” mla_caption=”{+template:({+description+}|{+caption+}|title)+}” link=”none” mla_itemwidth=”600px”]

    tax_operator=”NOT IN”-
    I tried using tag=primary tax_operator=”NOT IN” and it showed the images with the primary tag rather than excluding them. What am I missing?

    As I continue fine tuning, do you prefer that I start new threads rather than including questions here?

    Jeff

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with the good news about your progress. I am happy the Development Version is working for you.

    I am not sure why “the MLA zip file ended up in the media library“, but if the plugin is working you can just delete the ZIP file.

    Your technique of matching a primary image to detail images by Title is unusual, but it makes sense and works in your application; very creative.

    Sorting a galleryfile_name and name_only are MLA Data Sources; they are not in the IPTC/EXIF meta data embedded in your image files. You should delete the IPTC/EXIF mapping rule that’s not working and define a Custom mapping rule instead. The steps required are:

    1. Navigate to the Settings/Media Library Assistant “Custom Fields” tab.
    2. Make sure the “Enable custom field mapping when adding new media” box is checked. If not, check the box, scroll down to the bottom of the page and click “Save Changes”.
    3. Scroll down to the “Add a new Field and Mapping Rule” area.
    4. In the first text box, give your field a name, e.g., “image_file_sort_name”.
    5. From the Data Source dropdown list, select “file_name” (or “name_only”).
    6. In the “Existing Text” dropdown list, select “Replace”.
    7. In the “Format” dropdown list, select “Native”.
    8. Click the “MLA Column” check box to make the field available in the Media/Assistant submenu table. You can also click the “Quick Edit” and “Bulk Edit” check boxes to make the field available in the Media/Assistant submenu table Quick Edit and Bulk Edit areas if that’s useful for you.
    9. In the “Option:” dropdown list, select “Text”.
    10. Click the “Delete NULL Values” checkbox.
    11. Click the “Add Field and Map All Attachments” button to save your work and create the “image_file_sort_name” value for the items already in your Media Library.

    On the Media/Assistant screen you can now display an “image_file_sort_name” column. If you don’t see the column, pull down the Screen Options (upper-right corner) and check the box next to File Size. Each of the terms in the column is a link; click on a value to get a list filtered by that value. You can also sort the table on “image_file_sort_name” by clicking on the column header.

    You can use the meta_key, orderby and order parameters to sort an [mla_gallery] by your custom field. For example:

    [mla_gallery post_parent=all meta_key="image_file_sort_name" orderby=meta_value order=DESC]

    mla_itemwidth – If your intent is to limit large images to a maximum width of 600px, you can add size=large or size=full to your shortcode. The default, size=thumbnail, uses a 150×150 version of the image which is then centered in the 600px gallery-item container.

    tax_operator=”NOT IN” – You are missing a subtle and confusing WordPress historical quirk. The tag= parameter is a “Tag parameter”, not a “Taxonomy parameter” so the tax_operator= parameter does not apply. If you replace tag=primary with post_tag=primary (post_tag is the taxonomy slug for “Tags”) you will have a Taxonomy query that uses the tax_operator parameter.

    Since your recent post fine tunes the original topic you can keep using this topic. If you have a new, unrelated problem or question starting a new topic will be more useful.

    Plugin Author David Lingren

    (@dglingren)

    I have released MLA v2.01, which includes the [mla_gallery] and [mla_tag_cloud] improvements inspired by this topic.

    I am marking this topic resolved, but please update it if you have any problems or further questions regarding the [mla_gallery] features discussed above. Thanks for inspiring a new MLA feature and for your interest in the plugin.

    Thread Starter jhdean

    (@jhdean)

    With this enhancement you can access the following post-/page-level fields in data selection parameters:
    ‘page_title’ => $post->post_title,

    Hello David,

    In the following code,

    [mla_gallery columns=0 mla_search_fields=title s="{+page_title+}" tag="primary" mla_caption="<div class="detail-title">{+template:({+title+})+}</div><br>&nbsp;<br>{+template:({+description+}|{+caption+})+}" link="none" size=large]

    I tried using

    {+template:({+page_title+})+}

    to grab the page title instead of the image title but it didn’t work. The rather convoluted reason was that in order to have a link in the FooBox lightbox, I had to put it in the image title. This way I can link to the detail page from the title displayed within the lightbox. The problem then is that on the detail page, when I display the image title with the above code, it is in the form of a link instead of plain text and is rather confusing and redundant as it links to the same page where it is displayed.

    If it were possible to use the new enhancements in template code as well as selection parameters I could get around this. Would that be difficult to add or am I missing something that is currently possible?

    Thanks again for all your help,
    Jeff

    Plugin Author David Lingren

    (@dglingren)

    Thanks for quoting my earlier comment in you post. That comment is misleading; the post-/page-level fields are available throughout the shortcode process, not just in data selection clauses. The comment was responding to the original question about the keyword search parameter.

    I entered the following code in my test system:

    [mla_gallery ids=2027 mla_caption="<div class='detail-title'>{+template:({+page_title+})+}</div><br>&nbsp;<br>{+template:({+description+}|{+caption+})+}" link="none" size=large]

    My gallery display shows the page title, as expected, below the thumbnail image; I believe this is what you are trying to do. Note that I made two changes from your example:

    1. I replaced your data selection parameters with a simple ids=2027 parameter just to select an image for the gallery. I don’t think this is material.
    2. I replaced the double quotes around 'detail-title' with single quotes to avoid the “tax query error” message.

    As far as I can tell the new post-/page-level values are available for Content Templates. If I am missing something from your explanation of the issue, any additional information you can provide will let me be more specifically helpful; thanks.

    By the way, if you add exact=true to your shortcode it will generate a simpler, faster database query to process the s="{+page_title+}" search.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Generic shortcode for page generated from thumbnail link’ is closed to new replies.