473,770 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="secti on1"
?>

Included navigation.php file

<li<?php if ($Section=="sec tion1") echo " class=\"selecte d\""; ?>><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 1762
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
2409
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. I'm thinking of linking to a site map (server driven) that would highlight the position in the site as a no javascript alternative. Ideas or comments??? Jeff
1
2762
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 colspan="2">Header</td> </tr>
2
2585
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 7.51, even though it displays fine in Mozilla 1.6, Firefox 0.9, Netscape 7.1 and Internet Explorer 6.0 Hope someone can help!
3
5478
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. I'm using Infragistics Ultra Web Navigator, which can load the menus from an XML file, so the navigation requirement is taken care of. I had created a generic aspx file that accepts the static content filename as a query string. The ASPX form...
1
1599
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 how to allow visitors to bookmark "pages" when the page is dynamic. I can use Apache-style pseudo-urls to parse out the location of the dynamic content, like... http://fakepage.gov/foo/20345583 or...
8
2257
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 to add comments at the bottom of each page, similar to the way the php, mysql, apache manuals work. PUNCHLINE_A:
0
911
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 links on the subject its an ASP.NET 1.1 app tia
71
4861
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? http://www.review-a-gadget.com/ Is there anything obvious that I am missing? Are there problems with some browsers? Please let me know if you notice anything.
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10257
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8931
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.