473,386 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Dynamic site navigation

Hope someone can help me out with something - I'm a HTML/CSS developer
who know's a little PHP, which I use to make smaller sites
semi-dynamic, I want to expand on what i'm currently doing but need
some help.

I currently use PHP to create a single included .php file that contains
the navigation, that knows via a variable hard-coded in the XHTML page,
what section that page is from and them marks the navigation <li> with
a class the highlights it.

Here's the code I currently use

XHTML page

<?php
//Section identifier - numbered or named'
$Section="section1"
?>

Included navigation.php file

<li<?php if ($Section=="section1") echo " class=\"selected\""; ?>><a
href="#" title="">Home</a></li>

So (eventually) I get to my question... Rather than having a variable
written into the top of each page, could I create a globals.php file
that's included from everypage that knows what section that page is is
from it's parent folder.

So if I hard-coded the folders/variables in this page, then the page
recognises which folder it's from and applys that variable to the
navigation.php

Any help much appreciated

Jay

Apr 11 '06 #1
1 1739
NC
James Bates wrote:

Hope someone can help me out with something - I'm a HTML/CSS
developer who know's a little PHP, which I use to make smaller sites
semi-dynamic, I want to expand on what i'm currently doing but need
some help.
OK, but you may consider a change in the way you do things. Static Web
sites store content in files, with content embedded into presentation.
With a dynamic Web site, you have more options; you can (1) separate
contrent from presentation, and/or (2) choose to store content (whether
still attached to presentation or not) in files or in a database.
I currently use PHP to create a single included .php file that contains
the navigation,
Note that the reverse is also possible. You can have an index.php
file, which contains navigation, include content drawn from files or a
database.
So (eventually) I get to my question... Rather than having a variable
written into the top of each page, could I create a globals.php file
that's included from everypage that knows what section that page is is
from it's parent folder.


Yes. If your globals.php is included into another file, the
superglobal variable $_SERVER['PHP_SELF'] will tell it into what file
it has been included.

Try this: create two files, a.php and b.php.

a.php:

<?php include 'b.php'; ?>

b.php:

<?php
echo '<p>PHP_SELF=', $_SERVER['PHP_SELF'],
'</p><p>__FILE__=', __FILE__, '</p>';
?>

Then point your browser to a.php; the output will be:

PHP_SELF=/A/a.php
__FILE__=/A/b.php

In other words, b.php "knows" that its name is b.php and that it's been
included into a.php.

Cheers,
NC

Apr 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeff Thies | last post by:
I have a site with javascript navigation menus (it's in the design spec). There's a bit too many pages to do a bread crumb type alternate nav, and no natural index page for each site section. ...
1
by: Richard Jenkins | last post by:
Hi. I'd appreciate some comments/help with this site: http://www.moonremovals.co.uk/new The aim is to use css positioning to recreate something similar to: <table> <tr> <td...
2
by: Martin Doyle | last post by:
Ok, I'm building a JS-based limitless-sublevel dynamic menu and am making it cross browser as well - 3 packs of aspirin so far and counting ;) I'm having a weird rendering problem using Opera...
3
by: Buddy Robbins | last post by:
Hey folks, I am re-writing an ASP.Net site for a company. The client wants to be responsible for the static content and navigation of their site, and I'll be responsible for any dynamic content. ...
1
by: Razzbar | last post by:
I'm creating a site that is all on one page. The navigation of the site is enabled by a hidden iframe that fetches content from the server and re/places it in a div on the page. The problem is...
8
by: Sandy Pittendrigh | last post by:
I have a how-to-do-it manual like site, related to fishing. I want to add a new interactive question/comment feature to each instructional page on the site. I want (registered) users to be able...
0
by: Freddie | last post by:
hi, i need to add navigation links on top of all pages on a quite large site, theese depend on user rights, time of the day and some external conditions can u plz share some best practices and...
71
by: Murray R. Van Luyn | last post by:
Hi, Since I have made changes to my website it's been a complete flop. According to the logs, as soon as visitors have downloaded the index page they are off. I can't figure out why? ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.