Archive for April 27th, 2009
27th April
2009
I’ve recently added some links on my other blog that I wanted to ensure the paths were not clear to anyone viewing the blog. You may need to do this on your WordPress blog also, so if so, here’s how you do it:
- Create a directory to store all your external redirect links in. I chose “Go”, but you could call it “Redirect” or “External”.
- Add a file to this directory, which is simply a php file that contains all the info about your external links. My file is called merchant.php, because I have links out to various merchants from my file.
- In your redirect file, you will need to have an array of the various different url’s that you want to link to. If you have distinct groups of websites taht you wish to link to, it’s best to have more than one array. Your arrays should be set up so that you have a key and a val, for example: array(key1=>val1, key2 => val2)
- If you are using more than one array, you will need to pass the array and the key of the url to your redirect script. I used the variable names $a for the array and $n for the number of the key.
- If you have more than one array, you will need a switch statement, to ensure that you pull the correct url from the correct array, here’s an example of how to do this:
- You will need to acquire the variables $a and $n from the query string, like this:
- To use this in a post or a page, you’ll need to make your links like this:
- Upload and test to make sure it works!
switch ($a)
{
case “array_1″:
$url = $array_1[$n];
header (”Location: $url”);
exit;
case “array_2″:
$url = $array_2[$n];
header (”Location: $url”);
exit;}
$a = $_GET['a'];
$n = $_GET['n'];
<a href=”<?php echo get_bloginfo(’url’); ?>/go/redirect.php?a=array_1&n=1″>Link to redirect urk</a>
0 Comments