0

I'm dealing with a problem I can't solve myself. I did a few hours of research about it, but I didn't manage to make it work. I want to send a parameter via the url to the page I'm forwarding to and based on the value of this I want to show a image. Im using the Hana Code Insert Plugin to get my js used in WP. I'm relatively new to WP and have little to no knowledge in PHP, so please consider this.

The Hana-contents are as following:

shortcut galleryLink and getSelected_05: http://www.abload.de/gallery.php?key=updfCGrl

The contents of the site are as following:

toat.me/test-for-ids/

Gallery: [hana-code-insert name='galleryLink' /] Finished...

toat.me/resize-your-image-now/

|img class="aligncenter size-full wp-image-119" alt="" src="http://toat.me/wp-content/uploads/2013/08/blank-t-shirt_white_big.jpg" width="700" height="700" /| [hana-code-insert name='getSelected_05' /]

Note: I had to replace the <> tags of the img with | in order to show it in this post. I'm looking forward to helpful answers.

1 Answer 1

1

If you are working in a php file such as a template, you can use $_GET to extract the url variables. For example, if your url was mydomain.com/page?color=blue you would print it on screen by:

<?php echo $_GET['color']; ?>

This would print "blue". So to make a conditional statement out of this, you could do:

<?php if( $_GET['color'] == 'blue' ) {
    echo '<img src=''>';
} elseif( $_GET['color'] == 'red' ) {
    //do something else
}

Query strings are stored in the $_GET variable as an associative array. Now, if you want to do query strings in Wordpress posts/pages, you need to create a function to read query strings via shortcode. It looked like you were doing this inside template files though so I will leave that solution out, unless you need it - then just let me know and I'll edit this.

2
  • As I said above, I use a plugin to get the code used in Wordpress posts/pages, I'm writing the code inside the plugin and then just access it with its shortcode. I tried it the way you described above, but it shows me the php code at the page and just the img-tag from the else is executed and it displays this picture
    – Schampion
    Commented Sep 4, 2013 at 9:17
  • Could you please edit your post to add the fuction to read query strings.
    – Schampion
    Commented Sep 5, 2013 at 14:28

Your Answer

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

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