HOWTO: Display some arbitrary HTML on a specific page based on the URL you are on
This snippet shows you how to insert simple "if" statements in your theme to display html or any other block of code based on the URL you are on. In the example it shows you how to display a block of text before printing out a taxonomy node listing.
1) open up page.tpl.php in your phptemplate theme.
2) Right above where it starts printing out your main content in your theme (usually starts with printing
menu tabs) you can insert some logic.
3) you can use some logic to figure out what page you are on. For instance for the URL:
http://www.example.com/taxonomy/term/10
arg(0) returns 'taxonomy'
arg(1) returns 'term'
arg(2) returns '10'4) If you want to display some html if you are on that
page, you put in some logic in your theme file (page.tpl.php).
<?php if(arg(0)=='taxonomy' & arg(1)=='term' & arg(2)== '10'): ?>
This is where you put the html you want to print out
on this page! It won't print this if we aren't on this
page.
<?php endif; ?>
MAIN CONTENTThat's all the php you have to type. The logic says, "If we are on the taxonomy/term/10 page, let's print
this html code. Otherwise let's skip it and continue to the main content." You can see that this is
powerful because it lets you display a block of HTML or code depending on what page you are on, which is useful in many situations. You can put this snippet anywhere in the theme file, and use it to load different pictures or text anywhere on the page. The arg() function is useful for returning the path of whatever page you are on. Of course, since it is a simple "if" statement you can use this example as a general purpose logic tool. For instance, let's say you want to only print out a block of code for the 100th user (user ID = 100) when they are logged in:
<?php global $user; if($user->uid == 100): ?>
Welcome, 100th user!!! This text will only display when you are logged in!!
<?php endif; ?>Hope that helps a bit.
Good luck!
zirafa

Working with aliased pages
Here is a handy solution if one needs to do some customizations based not on real path, but on current alias. For example, if you want to insert a custom image on all pages, starting from 'about', ex: 'about/mycar', 'about/myhome' etc:
<?phpif(strstr($_REQUEST[q], 'about') ===0) {
print '<img src="img/custom_about.gif" />';
} else {
print '<img src="img/default_about.gif" />';
}
?>
Note: '===' is not a mistake, it's to make sure 'about' is at the beginning of the string.
/Michael