1

I have a post gallery and I'm displaying the thumbnails in example.com/gallery. Now this thumbnails are created via posts and when you click on on eof the thumbnails, it will direct you to single.php template. It goes to display a gallery room which mimics a Gallery Exhibit created with HTML5 and CSS3. Its quite heavy to load and doesn't really have the standard web gallery feel and I want an option for users to click weather to view it in Gallery Room or the standard grid which the native WordPress Gallery has.

Now I want, in my example.com/gallery, to have two links. One on the Gallery Room and one on the standard grid. But how can I do this? I have already created a template for the standard gallery but how can I dynamically get the ID of the post whenever the user click on the 1st link in the example.com/gallery page.

I have this in my template:

$post_id = 527;
$queried_post = get_post($post_id);

527 being the post ID. But of course this is not dynamic. I want to pass that ID to a url by clicking a link and will be stored to a variable which will be the value of the $post_id.

Can anyone help?

thanks!

3
  • Are you asking how to pass information in a GET string in PHP?
    – s_ha_dum
    Jul 3, 2013 at 3:52
  • yes. Can you do that in WordPress?
    – mark lape
    Jul 3, 2013 at 4:42
  • Yes, same as in any other PHP application, just avoiding parameter names that WordPress uses.
    – s_ha_dum
    Jul 3, 2013 at 4:45

1 Answer 1

1

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; ?>
3
  • thanks Jenkins. So now the ID is in the URL, how can I pass that ID now in the template page?
    – mark lape
    Jul 3, 2013 at 5:04
  • 1
    Great! Now you can retrieve the post_id by doing a $_GET['my_gallery_id'];
    – JenkinsDev
    Jul 3, 2013 at 5:11
  • You just made a miracle Jenkins! All Good now. Thanks so much!
    – mark lape
    Jul 3, 2013 at 5:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.