Forum Moderators: coopster
I know nothing about PHP but have a little task to complete while our php developer is on holiday.
Using PHP I want to REQUEST_URI (I think this is the best way forward - please correct me if I am wrong) then use something similar to subString to get the first directory from the URI string i.e. http://www.example.com/THIS_DIRECTORY/ use this value to get our current location and display an image. So if we are in ABOUT directory we would display an image further down in the HTML in relation to our ABOUT PAGE.
Anyone able to help me out with the code?
With thanks in advance,
-Gs
[edited by: dreamcatcher at 8:20 am (utc) on Aug. 31, 2007]
[edit reason] Use example.com, thanks. [/edit]
I do this kind of thing all the time. Use PHP to set the class or ID of a containing <body> or <div> element, then use specific CSS to change the appearance of an element within the block.
<head>
<style type="text/css">
div.icon_div { height:32px;width:32px }
body#category_1 div.icon_div {background-image:url(images/image_cat_1)}
body#category_2 div.icon_div {background-image:url(images/image_cat_2)}
</style>
</head>
<body id="category_1"><div class="icon_div"></div></body>
"
/wp-content/uploads/cat1/" would become "wp-contentuploadscat1". I'd suggest using the method I outlined, along with some kind of templating mechanism to set the container class.
This is very powerful and flexible.
if ( $_GET['p'] )
{
$class = "xx_post_results";
$page_id = 'post_'.$_GET['p'];
}
elseif ( $_GET['page_id'] )
{
$class = "xx_page_results";
$page_id = 'page_'.$_GET['page_id'];
}
echo "<div id=\"$page_id\" class=\"$class\">";
Then use the method I outlined to display customized content.
I still consider pure php better approach - why mess css php when we can have what we want in 3 lines?
$a = explode("/", $_SERVER['REQUEST_URI']);
$b = count($a);
$dir_i_seek = $a[$b-2];
explaining the -2 part
because REQUEST_URI starts and ends with /, when you explode it you will get an array similar to:
{empty}
{dir1}
{dir2}
{last_dir} // this we seek
{empty}
this array has (n+2) elements, where n the number of our directories - first and last element are empty. In our example the count is 5.
Array elements begin couting from position 0.
Last element is (empty)
Thus we have the $dir_i_seek = $a[$b-2] part