Im looking for a way to show something on a page based on its url.
The way I setup my pages I have my template in 2 pages (header.php, footer.php) and use include on the top and bottom of new pages and insert the page in the middle.. If you understand that. I want to be able to show a small dropdown menu at the bottom based on what page the person is on. I want to be able to put this on the main template file so I dont have to copy the dropdown to every page and to let me update it easier.
Example: If Im on the main page and click on tutorials it would show a dropdown showing different tutorial headings for easier navigation.
Ive been trying this for a while with different codes but Im new to php so most is guessing or changing other code. ive never got just what i wanted.
If anyone could help it would be great.
Thanks,
Jonny
Php Question
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
viewtopic.php?t=37950 may be of use/help.
ok from what I read I came up with this:
Im gonna be in work for a while so can anyone tell me if it would work or if theres anything wrong with it.
Thanks,
Jonny
Code: Select all
<?
function geturl()
{
$ports = array('https' => 443, 'http' => 80);
$prefix = (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off" ? 'http' : 'https');
$url = $prefix;
$url .= '://';
$url .= $_SERVER['HTTP_HOST'];
$url .= $_SERVER['SERVER_PORT'] != $ports[$prefix] ? ':' . $_SERVER['SERVER_PORT'] : '';
$url .= $_SERVER['PHP_SELF'];
$url .= (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != "" ? "?".$_SERVER['QUERY_STRING'] : "");
return $url;
}
if ($url == http://name.com/) { ?>
<select name="name"><option selected="selected">Name</option>
<option selected="selected">Name2</option>
<?
}
?>Thanks,
Jonny
If you are including header and footer at the top and bottom of each page, then your scripts look like this right?
If that is the case, then you could just do something like:
Then in footer.php something like:
I think that would work...
Code: Select all
include("header.php");
/* script for stuff on page */
include("footer.php");Code: Select all
include("header.php");
/* script for stuff on page */
$current_script="home"; /* or whatever the name of the page is */
include("footer.php");Code: Select all
if ($current_script="home") /* switch would be better, but you get the idea */
{
/* populate array for drop down or whatever */
}
/* rest of footer code */- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
How much of the current page name do you need? I think you can use basename() to get the name of the current page. Set that page name to a var then use that var for comparison.
In the projects I have done using page names (which have been quite a few) I have used the current page name and directory name to decide which navigation to show users. That way they will see only those pages that are within the directory they in. Is this what you are after?
In the projects I have done using page names (which have been quite a few) I have used the current page name and directory name to decide which navigation to show users. That way they will see only those pages that are within the directory they in. Is this what you are after?