• So I’ve literally been faffing around with this for months now and I am getting quite frustrated (more with myself than anything).

    I’ve used various plugins / templates / custom code set up the functionality for my site’s members to create and manage photo albums from the frontend.

    The part I seem to be struggling with is how to display each album (CPT with the images as attachments) in an effective way. The posts are displayed under each member’s profile, as a thumbnail image, and when clicked it takes you to the post in question.

    For that post, I have created a template with a slider for the post attachments and a static sidebar, which has a few details of the album and also a comments section.

    The comments section is currently only for the parent post, and not for the individual images, but I would like it to be per attachment. I would also like to have options to download individual images or the entire album, but can’t seem to work out how I should be setting this post up, what should be templates, modals, lightboxes etc.

    I wanted to figure this out myself, which is why I have been messing around for months, but have come to the conclusion that it it feels more difficult than it should be. That is leading me to believe that I am going about this the wrong way and/or am missing something obvious.

    I hope I have explained this sufficiently. Any advice would be greatly appreciated ??

    • This topic was modified 4 years, 11 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic
Viewing 5 replies - 1 through 5 (of 5 total)
  • If you look at the Template Hierarchy, you will see that there is a template for attachments, and you can even get more specific for the mime types. The point being that they are “posts”, so can have their own comments, on their own pages. Most themes show the attachments with the same template as a post, so not much unique to the attachment is handled, but you can simply put the appropriately named template in and show the attachment details and even the Next/Prev links work for attachments in a gallery (done with a gallery shortcode). (Are you aware that putting [gallery] into the content of a post will result in a gallery of all attached images? And the default is to link to attachment page, I think.)

    Thread Starter hshah

    (@hshah)

    @joyously

    I had actually created a separate attachment template (about a month ago), and I had that showing the photo, it’s own comments section, download link etc.

    I don’t actually want to show the parent post though, and that is what I was having difficulty with. I couldn’t work out how to not open the parent post when clicking on its thumbnail, and instead load it’s attachments in a lightbox or modal which could be scrolled through (the attachment template I had made was a fullscreen one and looked like a modal/lightbox popup).

    The template for the post type should be to output the markup for the attachments it has. That can be as simple as [gallery] or if you have need for more detail, put it in there. But trying to bypass the URL for the parent doesn’t make sense. It does exist and is what ties the images together. Since each attachment has its own URL also, WordPress will happily show the visitor whatever content the matching template outputs. You can mess with the rewrite_rules parameter for the register_post_type call, but why?

    Thread Starter hshah

    (@hshah)

    All this is probably my lack of understanding and making things far more complicated than they need to be, so I do appreciate you taking the time to run me through these things.

    I was looking to bypass the parent post because it is just a container of sorts. It doesn’t have anything that I would want to show to the users. Clicking on the album and going straight to slides of the attachments just seemed like more of a natural flow.

    I suppose showing the parent post with the gallery, and have users click on an image to start the slides/lightbox wouldn’t be a bad thing… but I don’t think it solves the problem I have (or think I have lol).

    When I was playing around with the gallery, depending on the setting I chose, clicking an image either took me directly to the file, opened the attachment post, or loaded the image in a lightbox.

    I want it to open like a lightbox/modal but in that view, display the attachment post for which I have made a template. I want that to function exactly like a lightbox, allowing the user to scroll between them etc.

    Once again, all this is what I think I want / should have, so if any of this seems ridiculous, please feel free to say so ??

    Seems like what you need is for your parent post to output the attachment page links using the built-in thickbox syntax, like core does with the stuff it shows in modals.
    This is the link for a plugin’s details:
    <a href="site/wp/wp-admin/plugin-install.php?tab=plugin-information&plugin=wp-downgrade&TB_iframe=true&width=772&height=738" class="thickbox open-plugin-details-modal">View details</a>
    Or use a different thickbox or lightbox, if needed. The content of the lightbox doesn’t have to be just an image; it can be the attachment page with comments (since it’s an iframe).

    But there is value in having the post URL since that is what WordPress is querying on, and then that post shows whatever you want. And if your want comments on each image, you have to have separate URLs so that the commenting code works.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Post Attachment Gallery with Comments’ is closed to new replies.