• Hello, i am trying to develop a theme where there is a native gallery on the homepage. Visitors click an image and it opens to the images attachment page with a description of the image.

    I would like to add the rest of the gallery thumbnails underneath so visitors can keep clicking more images in the gallery instead of the back button.

    Right now I have the native gallery written into each image’s description with shortcode- but it’s incredibly cumbersome, and each image in the gallery must be specified directly, which is a nightmare if I wanna update the gallery with more photos, I would have to go back and add the photo to the gallery description of every other photo in the gallery.

    “<div class=”descriptions”>
    ELEPHANT IN THE ROOM
    <br>
    By: Jayes Caitlin
    Date: 2017
    Media: 9 color silkscreen
    Size: 12×16″

    GLOWS IN THE DARK

    $60

    [wp_cart_button name=”ELEPHANT IN THE ROOM” price=”60.00″]
    </br></br>
    [gallery type="rectangular" columns="4" ids="2477,2478,2479,1939,1928,1906,1905,1893,1859,1340,1273,1271,1230,1216,1215,992,1718" orderby="rand"]
    <br>
    <br>
    </br></br>

    </div>”

    I’m sure there is a better way to add the code the php attachment page, but I can’t figure out what bits of code to use and where to put it exactly. My theme does not have a php page for attachment pages.

    I am using aav1

    Take a look:

    https://jayescaitlin.com/

    Thanks!

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    My approach would be to forget about attachment pages. I would create a custom gallery post template to use when the native gallery is inserted into post content. There’s various ways to get a particular template used when a gallery is created. I would create a custom post type just for gallery posts. If the post type is “gallery”, name the template single-gallery.php.

    It would work like a normal single post template, except there is a large div container above the normal post content. When the page loads, the first image in the gallery list is displayed in this div. It can also contain any caption plus other desirable data.

    When someone clicks on a thumbnail image below, instead of opening the attachment page, jQuery intercepts the event and cancels the default action, and instead loads the full size image with its associated data in the large div container via AJAX. Then the user experience is closer to a slideshow type of plugin, but you can utilize the default media library to build the galleries.

Viewing 1 replies (of 1 total)
  • The topic ‘PHP code to add native galleries to attachment pages’ is closed to new replies.