Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

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

1 Answer 1

up vote 1 down vote accepted

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; ?>
share|improve this answer
    
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 '13 at 5:04
1  
Great! Now you can retrieve the post_id by doing a $_GET['my_gallery_id']; –  JenkinsDev Jul 3 '13 at 5:11
    
You just made a miracle Jenkins! All Good now. Thanks so much! –  mark lape Jul 3 '13 at 5:17
    
Glad I could help and thanks for accepting the answer. –  JenkinsDev Jul 3 '13 at 5:19
    
Thanks very much! –  mark lape Jul 3 '13 at 5:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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