How can I pass the ID of a post to a page template by clicking a url?

When clicking a link from a post to a page you can concatenate the post_id to the end of the link as a GET variable.

So let’s say you had a link within the WordPress loop you can easily add the post_id as a GET variable as such

<?php if (have_posts()): while(have_posts()): the_post(): ?>
        <a href="http://example.com/gallery?my_gallery_id=<?php echo $post->ID; ?>">Gallery</a>
<?php endwhile; endif; ?>

So with just the URL you would have:

http://example.com/gallery?my_gallery_id=<?php echo $post->ID; ?>

tech