• Resolved wholemilklatte

    (@wholemilklatte)


    I think this is probably pretty straight-forward – i’m digging through the docs right now and interested in any pointers.

    Here’s what i’m trying to do:
    – Create a page that’s simply a grid view of every image associated with posts of a specific type (these posts all have a single image in them)
    – The grid specifics should be editable (columns, rows, image size, image order based on the date of the post the image is in etc, nothing crazy)
    – Mouseover / hover over each image should show the post title that image is from
    – Clicking on the image should take you to the specific post that image is part of.

    I’ve been starting to work through this with MLA, i’m not sure yet how to reference the posts (and pull the images from them), rather than get the images directly out of the library using a category.

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

    (@dglingren)

    Thanks for an interesting question. The current MLA version will not support this application directly but I may be able to make a few changes to fix that. The basic approach would be 1) generate a list of the custom post type IDs, then 2) pass the list into [mla_gallery] as post_parent values to generate a gallery of those items.

    This approach will work if and only if the images within the posts are “attached” to the post, i.e. the post_parent is set correctly. There is no other way to look in the post content and extract the ID of the embedded image (unless you want to write some PHP code).

    First, to get the list of post IDs you can use an [mla_gallery] shortcode with post status and post type parameters, something like this:

    [mla_gallery post_type=post post_status=publish post_mime_type=all post_parent=all]
    

    Where post_type is your custom type. You can add other parameters such as the post date or category to filter the list.

    Second (this is the missing part), pass the list of post IDs to a second [mla_gallery] shortcode that will display a gallery of the images. This would use the “Support for Other Gallery-generating Shortcodes” as described in the Settings/Media Library Assistant Documentation tab. The “grid specifics” could be edited by using MLA’s custom markup and style templates.

    The current version won’t support [mla_gallery] as the alternate shortcode because there’s no easy way to parse out which parameters go to the first shortcode and which go to the second. If this approach looks promising to you I can investigate some way to fix that.

    I should note that the current MLA version does support a gallery display that uses the “Featured Image” of a post as the gallery thumbnail. If that would work for you, let me know.

    I will leave this topic unresolved until I hear back from you. Thanks for a stimulating idea and for your interest in the plugin.

    Thread Starter wholemilklatte

    (@wholemilklatte)

    Cool, thanks for the help!

    I’ll see if i can give this a go later tonight or tomorrow. i’ll report back.

    Thread Starter wholemilklatte

    (@wholemilklatte)

    (apologies, i’ve been mucking with the metadata and taxonomy with the site i’m building. i haven’t been able to try this yet)

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your updates. The delay is not a problem.

    I did some testing and found a problem with the “Featured Image” thumbnails in the current MLA version. If you decide to give that a try I will upload a Development Version with the fix.

    I am travelling from 5/24 until 5/30. I will look for an update after my return.

    Plugin Author David Lingren

    (@dglingren)

    I have uploaded a new MLA Development Version dated 20210531 that contains the “Featured Image” thumbnails fix. You can find step-by-step instructions for using the Development Version in this support topic:

    PHP Warning on media upload with Polylang

    Let me know if you get a chance to try the Development Version and how the “Featured Image” thumbnail feature works for your application. Thanks for your patience.

    Plugin Author David Lingren

    (@dglingren)

    I have completed some enhancements to the [mla_gallery] shortcode that support the solution I outlined in my earlier post. The new mla_alt_shortcode=yes parameter value allows you to use mla_gallery as your alternate shortcode and the new mla_alt_parameters parameter lets you pass MLA-specific parameters through to the alternate shortcode.

    I have uploaded a new MLA Development Version dated 20210727 that contains the enhancements. You can find step-by-step instructions for using the Development Version in my previous post. Once the Development Version is installed you can code something like the following to get the results you seek:

    [mla_gallery post_type=post post_status=publish post_mime_type=all post_parent=all category=abc mla_alt_shortcode=yes mla_alt_ids_name=post_parent mla_alt_parameters="mla_link_href='{+site_url+}/?page_id={+parent+}'"]
    

    The above example first selects all WP posts assigned to the “abc” category and then passes their ID values to the alternate shortcode as a post_parent= list. The mla_link_href='{+site_url+}/?page_id={+parent+}' parameter is ignored by the primary shortcode and passed along to the alternate shortcode for processing. It makes each link behind the gallery thumbnail go to the post to which the image is attached.

    You can change the post_type=post parameter to access your custom post type and remove the category=abc parameter to get all instances of the type, or substitute other data selection parameters that make sense for your application.

    In your first post you wrote “Create a page that’s simply a grid view of every image associated with posts of a specific type (these posts all have a single image in them)“. You don’t specify what “in them” means but I assume they are embedded in the content of the post; is that right? The solution I propose requires the images to be “attached” to the post in which they appear. You can use the tools in the MLA Insert Fixit example plugin to attach the items, as outlined in this earlier topic:

    post parent, link images

    The layout of the MLA Insert Fixit UI is a bit confusing (which I will work on). The “Post Type(s)” text box is located in the “Copy ALT Text between Media Library items and Post/Page inserts” section, but it is also used by the tools in the “Attach Media Library items” section. You can enter the name/slug value of your custom post type to make those tools work for your application.

    I hope that gets you started on a solution. It would be great if you can give the Development Version and example plugin a try and let me know how they work for you. I will leave this topic unresolved until I hear back from you. Thanks for your patience and for inspiring these MLA improvements.

    Plugin Author David Lingren

    (@dglingren)

    I have released MLA version 2.97, which includes the [mla_gallery] enhancements outlined above, the MLA Insert Fixit UI update and some other improvements and fixes as well.

    I am marking this topic resolved, but please update it if you have any problems or further questions regarding the above suggestions and MLA changes. Thanks again for an interesting application idea.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Images from Custom Post Type’ is closed to new replies.