Linking Gallery Images to page that shows the same images in a different order

I have a custom-post_single.php page which outputs a gallery in a template-ed format where the images are small and in a design. I need the user to be able to click into any of the images and be redirected to another page that has the same images/post content but larger and in a vertical line scroll format.

How do I go about creating this secondary page based on whatever information the custom-post_single.php generates per post.
THANKS!

  • Adam Czajczyk

    Hello Kate,

    I hope you're well today and thank you for your question!

    I think the simplest solution here would be to create an additional template for post. However, as WP doesn't support multiple templates for the same post-type "out of the box" a small workaround would be necessary.

    This plugin will allow you to use/select additional custom templates for single post:
    https://wordpress.org/plugins/single-post-template/

    Next step would be to create a custom template file (just like you already did) that would suit layout that you'd like to achieve and - in this case - possibly "hardcoded" data, meaning you'd want to explicitly define what content would be fetched from WP with this template.

    Make sure that this template file includes header such as below:

    <?php
    /*
    Single post Template: My Custom Template
    */

    Last step would be to create new (empty) post and assign this new template to it (there'll be a drop-down list of available additional templates right below the content editor) and link to it from images of your original post.

    I hope that helps!

    Best regards,
    Adam

  • Kate Eldridge

    Thank you for your response!
    I have a few questions for you if you wouldnt mind taking a look.

    "Next step would be to create a custom template file (just like you already did) that would suit layout that you'd like to achieve and - in this case - possibly "hardcoded" data, meaning you'd want to explicitly define what content would be fetched from WP with this template."

    1) Do I need to make a new custom post type for this in a plugin or just making a template file like you mentioned above?

    2) How do I reference the content that I want to be pulled? For now it could just pull the_content()

    "Last step would be to create new (empty) post and assign this new template to it (there'll be a drop-down list of available additional templates right below the content editor) and link to it from images of your original post."

    1) Post or page? if post, would this be a post in the custom post type I've made or just regular old posts?

    Thanks so much!
    Kate

  • Rupok

    Hi Kate Eldridge

    I hope you had a wonderful day.

    About #1: @Adam Czajczyk gave you reference of a plugin so that you don't need to create a custom post type.

    About #2: You can pull the exact same content with the_content() in your new custom post template.

    About #3: Post. As you are not creating any new custom post type, rather you are creating a new post type, the post will be shown according to the template you choose from the right sidebar.

    Have a nice day. Cheers!
    Rupok

  • Kate Eldridge

    @Rupok and @Adam Czajczyk Thank you. After reviewing your notes and the plugin documentation more thoroughly I was able to get this running. However, wondering if there is a way to make this more automated so my client doesn't have to manually make the same gallery more than one and output on 2 different pages.

    I've been looking at advanced custom fields to do this, but also thought there might be some code I could write.

    If there's not an answer, maybe some sort of gallery plugin that names galleries might be helpful.

    Thanks for all your help.

    Kate

  • Kasia Swiderska

    Hello Kate,

    I'll just jump here with suggestion - please note that I didn't test this solution - there is function get_post_gallery() https://codex.wordpress.org/Function_Reference/get_post_gallery
    You can give it post ID and it will get gallery from that post and you can display it on other page.

    So lets assume you have page template where you will take ID of post from url and then use it in this function get_post_gallery() to get images.
    Main problem is how to pass ID in url - because with galleries you can't set custom url to image. But you can always do this with jQuery script.
    Create new page - call it like Big gallery (slug will be big-gallery).
    In this page custom template have code like this

    $postGallId = &_GET('post_ID');
    
      $gallery = get_post_gallery( $postGallId, false );

    and the rest to display gallery.

    In the single post you would need to add jQuery script that will change url of images in gallery to something like this:

    http://mysite.com/big-gallery/?post_ID=123

    jQuery script would look like that:

    var newUrl = 'http://mysite.com/big-gallery/?post_ID=' + <?php get_the_ID(); ?>;
    $('.gallery-item a').attr('href', newUrl');

    this is very rough draft of how this could work, but I believe it can be done.

    Kind regards,
    Kasia

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.