Jump to content
xisto Community
moldboy

Dynamic Included Menus path specification

Recommended Posts

I am looking for a way to make a dynamic menu using php and include, basicly I want to make a file that contains html formating source and links and include it somewhere in all my pages, the problem is that links are taken literaly and refered to as to where the html is running from. So is there a way I can make a file and include it in my pages, then it will determin where the page is running from, and generate the links with an approperate amount of ../../'s so if my index is at root, but every section has it's own folder, I want to be able to include this file in all the pages, and have the path to the pages changed.I don't expect anyone to spoon feed me the code, but any suggestions would be apprecieated.

Share this post


Link to post
Share on other sites

In my opinion, it is usually a better idea to specify the value of hypertext references (the 'href' element of an 'a' HTML tag) relative to the root directory of your site rather than relative to the current directory - such as, for example, in '/folder/subfolder/index.html', use '<a href="/folder2/page.html">' rather than '<a href="../../folder2/page.html">'. It may sometimes mean adding a bit more text, but it also means it is easier for clients to locate files.Anyway, if you are generating your menu dynamically, it would probably be a better idea simply to 'echo()' (or otherwise send as output) the HTML code from the PHP script being used. I don't know why you would need to re-create the menu every time it is viewed, but you obviously have your reasons.

Share this post


Link to post
Share on other sites

I don't know why you would need to re-create the menu every time it is viewed, but you obviously have your reasons.

Correct me if I'm wronf but a <a> link will go relative to a page, so as in the site I'm about to outline:
/index.html
/fol1/index.html
/fol1/index2.html
/fol2/home.html
/fol2/home2.html

If I were on /index.html and clicked a link that pointed to <a href="fol1/index.html"> that could bork, but if I were on that page and clicked a link to <a href="fol2/home.html"> the client would look in (root)/fol1/fol2/home.html because it would be looking up from the current page, if if I were to make a file and using include add it to all my pages then on every page it would link to the files as fol#/filename.html whether or not that file actualy exists, so I would make my navigation so it worked on the root index.html page, yet when that same navigation would be included in any other page not only would the home link not work, but none of the other links would either, that is because the link <a href="index.htm"> from /fol2/home2.html would report a 404 because there is no file at /fol2/index.html

<a href="/folder2/page.html">' rather than '<a href="../../folder2/page.html">

That being said please tell what you mean by the above code, maybe I missed something.

Share this post


Link to post
Share on other sites

Uh, yes... I think you're missing what I said. A hypertext reference is treated by the client as relative to the current directory (and directories are obviously delimited by a '/'). Which is why I said that I think you should always specify a link's path relative to the root directory of the site, NOT relative to whatever directory you are currently in.So if you were current viewing '/fo1/index.html' and wanted to get to '/fo2/index.html', then in my opinion, it would be better to specify a link to '/fo2/index.html' rather than '../fo2/index.html'. Or if you were currently viewing '/fo1/fo2/fo3/fo4/file.html' and wanted to get to '/fo1/index.html', then you should use '/fo1/index.html' as opposed to '../../../index.html'.Anyway, you're obviously free to create your web pages however you wish.

Share this post


Link to post
Share on other sites

What Spectre is talking about is absolute (/) and relative (../) URLs. The only time you should really use relative URLs is when the links are in the same folder (or in a sub-folder within that folder) as the page accessing them. Whenever you link to anything in a directory above the one you're in, you're better off using absolute URLs which start from the / which is the root of your directory and then work down.

Share this post


Link to post
Share on other sites

i think its better convert html file in to JS file and thenuse scriptlike :<script src=your address></script>include its very slow but this script load pages and element fast :)

Share this post


Link to post
Share on other sites

i think its better convert html file in to JS file and thenuse script
like :
<script src=your address></script>
include its very slow but this script load pages and element fastĀ  ;)

What a load of rubbish. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.