PDA

View Full Version : links in footer template based on page name - ideally using php


ched999uk
09-12-2008, 08:25 PM
I am trying to add external links to the footer template. I dont want the same link on every page. So I have say 10 links that I want distributed in the footer on the pages, I only want 1 link per page. I want the links to always be tied to the page ie when ever pagexyz is opened link1 is displayed.

I wrote a bit of php to count the number of character in the page name and use that in a case statement.
But php wont run in the footer template. So does anyone have any ideas?
This is the php that I was going to use:

<?php
$theUri = $_SERVER['REQUEST_URI'];
$theUriLength = strlen($theUri);
while ($theUriLength >9)
{
$theUriLength = $theUriLength-10;
settype($theUriLength,'integer');
}
switch ($theUriLength){
case "0":
print "<a href='http://www.one.com' target='_blank'>Site 0</a>";
break;
case "1":
print "<a href='http://www.two.com' target='_blank'>Site 1</a>";
break;
case "2":
print "<a href='http://www.three.com' target='_blank'>Site 2</a>";
break;
case "3":
print "<a href='http://www.four.com' target='_blank'>Site 3</a>";
break;
case "4":
print "<a href='http://www.five.com' target='_blank'>Site 4</a>";
break;
case "5":
print "<a href='http://www.six.com' target='_blank'>Site 5</a>";
break;
case "6":
print "<a href='http://www.seven.com' target='_blank'>Site 6</a>";
break;
case "7":
print "<a href='http://www.eight.com' target='_blank'>Site 7</a>";
break;
case "8":
print "<a href='http://www.nine.com' target='_blank'>Site 8</a>";
break;
case "9":
print "<a href='http://www.ten.com' target='_blank'>Site 9</a>";
break;
default:
print "<a href='http://www.default.com' target='_blank'>Site 1</a>";
}
?>

Cheers for any suggestions on how I can solve the problem.

Dismounted
09-13-2008, 11:46 AM
You cannot run PHP in templates, you can run them in plugins. Create a plugin at global_start with your code, substituting print() with a variable assignment, and use that variable in the footer template.

ched999uk
09-13-2008, 01:46 PM
Thanks very much for that it really helped. That has helped me with my first ever mod.
Cheers:)