tushar707 Posted May 13, 2007 Share Posted May 13, 2007 Hello, i have a CSS menu. I want to do a php include command on every one of my pages on the website. any help on how to do this? Do i need a dynamic site to do this, or is a static site good enough to do php include Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/ Share on other sites More sharing options...
mmarif4u Posted May 13, 2007 Share Posted May 13, 2007 Please explain ur q more... Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-251758 Share on other sites More sharing options...
tushar707 Posted May 13, 2007 Author Share Posted May 13, 2007 basically I have a simple css menu based of images in a separate php file. I want to do a php include command on my website. is this possible? I want to do a php include command on the home page and every other page on my website for the menu. I am running a static website. I tried this: <?php include("menu.html"); ?> but nothing shows up. Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-251767 Share on other sites More sharing options...
chronister Posted May 13, 2007 Share Posted May 13, 2007 I have a Stupid Question .... do your pages your including this in all end in .php?? If yes, then <?php include("menu.html"); ?> should work You have to be aware of your directory structure. if your trying to include into /folder1/folder2/file.php and your menu.php file is in /menu.html You would have to use <?php include("../../menu.html"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-251794 Share on other sites More sharing options...
tushar707 Posted May 13, 2007 Author Share Posted May 13, 2007 no they end in .html how do i chance html files into php can I just save them as php files? These are static pages and not connected to server Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-251942 Share on other sites More sharing options...
tushar707 Posted May 13, 2007 Author Share Posted May 13, 2007 also one more thing. I will also be doing an include command for the content. Is it possible somehow that when I click a link on my css menu, it just changes the content and I dont have to reload the page? I am new to php. but found the include command online which I see as very very useful. any help will be appreciated a lot. Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-251951 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 Save menu.html as menu.php (you don't need to change anything in the code, just have HTML in the PHP file. <?xml version="1.0"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Page Title</title> </head> <body> <?php include("menu.php"); ?> <!-- Rest of code --> </body> </html> Sample menu.php file: <div id="menu"><a href="index.php">Home</a> | <a href="contact.php">Contact</a></div> Output: <?xml version="1.0"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Page Title</title> </head> <body> <div id="menu"><a href="index.php">Home</a> | <a href="contact.php">Contact</a></div> <!-- Rest of code --> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-251981 Share on other sites More sharing options...
textbox Posted May 13, 2007 Share Posted May 13, 2007 Having a page display 'current' data depending on the users actions can be done a few ways. Some ways people will tell you not to go with (for accessibility reasons) and others will always be winners. You could load your new pages in different frames, iframes, divs, layers etc. You could link to another include within the same file. Try looking these things up on google. Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-251987 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 If I were you I'd go for <divs> with simple JavaScript to edit the content of them. Frames are too old in my opinion. This is what I would do: Menu <a href="#" onclick="onclick="document.getElementById('content').innerHTML = 'This is the homepage.';">Home</a> | <a href="#" onclick="onclick="document.getElementById('content').innerHTML = 'This is the contact page.';">Contect</a> Where you want the main content to be displayed <div id="content" name="content">Default value</div> Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-251989 Share on other sites More sharing options...
textbox Posted May 13, 2007 Share Posted May 13, 2007 Frames are too old in my opinion. Same here, however I find they are a usefull starting point for beginners as frames are what lead to iframes/divs etc etc.... Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-251992 Share on other sites More sharing options...
tushar707 Posted May 13, 2007 Author Share Posted May 13, 2007 okay. should I also save my index file as php? and how do I test php pages locally? thanks for the code for the javascript. I will try that immediately. Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-251998 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 The index file can be left as HTML, but you will need to install PHP to test locally so I suggest you upload it. Can you paste your current menu please and I'll convert it to how it should be Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-252000 Share on other sites More sharing options...
tushar707 Posted May 13, 2007 Author Share Posted May 13, 2007 Here is my menu. thanks for all the help!!! My menu isn't completely done yet, as I have to change the some of the buttons. but I can do that later right? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Suckerfish Dropdowns - Vertical</title> <style type="text/css"> body { font-family: VladimirScrD; font-size: 24px; } #nav, #nav ul { /* all lists */ padding: 0; margin: 0; list-style: none; float : left; width : 149px; } #nav li { /* all list items */ position : relative; float : left; line-height : 29px; margin-bottom : -1px; width: 144px; } #nav li ul { /* second-level lists */ position : absolute; left: -999em; margin-left : 144px; margin-top : -1.20em; } #nav li ul ul { /* third-and-above-level lists */ left: -999em; margin-top : -29px; } #nav li a { width: 5em; w\idth : 5em; display : block; color : #1463a5; font-weight : 300; text-decoration : none; border : none; background-image: url(images/button.jpg); padding-top: 0; padding-right: 0em; padding-bottom: 0; padding-left: 1em; } #nav li a:hover { color : white; background : url(images/button_rollover.jpg); } #nav li:hover ul ul, #nav li:hover ul ul ul, #nav li.sfhover ul ul, #nav li.sfhover ul ul ul { left: -999em; } #nav li:hover ul, #nav li li:hover ul, #nav li li li:hover ul, #nav li.sfhover ul, #nav li li.sfhover ul, #nav li li li.sfhover ul { /* lists nested under hovered list items */ left: auto; } #content { margin-left : 6em; } </style> <script type="text/javascript"><!--//--><![CDATA[//><!-- sfHover = function() { var sfEls = document.getElementById("nav").getElementsByTagName("LI"); for (var i=0; i<sfEls.length; i++) { sfEls.onmouseover=function() { this.className+=" sfhover"; } sfEls.onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); } } } if (window.attachEvent) window.attachEvent("onload", sfHover); //--><!]]></script> </head> <body> <ul id="nav"> <li><a href="#">Home</a> </li> <li><a href="#">Our Programs</a> <ul> <li><a href="#">Climbing perches</a></li> <li><a href="#">Labyrinthfishes</a></li> <li><a href="#">Kissing gouramis</a></li> <li><a href="#">Pike-heads</a></li> <li><a href="#">Giant gouramis</a></li> </ul> </li> <li><a href="#">Resources</a> <ul> <li><a href="#">Burrowing gobies</a></li> <li><a href="#">Dartfishes</a></li> <li><a href="#">Eellike gobies</a></li> <li><a href="#">Gobies</a></li> <li><a href="#">Loach gobies</a></li> <li><a href="#">Odontobutidae</a></li> <li><a href="#">Sandfishes</a></li> <li><a href="#">Schindleriidae</a></li> <li><a href="#">Sleepers</a></li> <li><a href="#">Xenisthmid</a></li> </ul> </li> <li><a href="#">Events</a> <ul> <li><a href="#">Burrowing gobies</a></li> <li><a href="#">Dartfishes</a></li> <li><a href="#">Eellike gobies</a></li> <li><a href="#">Gobies</a></li> <li><a href="#">Loach gobies</a></li> <li><a href="#">Odontobutidae</a></li> <li><a href="#">Sandfishes</a></li> <li><a href="#">Schindleriidae</a></li> <li><a href="#">Sleepers</a></li> <li><a href="#">Xenisthmid</a></li> </ul> </li> <li><a href="#">Testimonials</a> <ul> <li><a href="#">Burrowing gobies</a></li> <li><a href="#">Dartfishes</a></li> <li><a href="#">Eellike gobies</a></li> <li><a href="#">Gobies</a></li> <li><a href="#">Loach gobies</a></li> <li><a href="#">Odontobutidae</a></li> <li><a href="#">Sandfishes</a></li> <li><a href="#">Schindleriidae</a></li> <li><a href="#">Sleepers</a></li> <li><a href="#">Xenisthmid</a></li> </ul> </li> <li><a href="#">About Me </a> </li> <li><a href="#">Contact Us </a> <ul> <li><a href="#">Burrowing gobies</a></li> <li><a href="#">Dartfishes</a></li> <li><a href="#">Eellike gobies</a></li> <li><a href="#">Gobies</a></li> <li><a href="#">Loach gobies</a></li> <li><a href="#">Odontobutidae</a></li> <li><a href="#">Sandfishes</a></li> <li><a href="#">Schindleriidae</a></li> <li><a href="#">Sleepers</a></li> <li><a href="#">Xenisthmid</a></li> </ul> </li> </ul> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-252009 Share on other sites More sharing options...
tushar707 Posted May 13, 2007 Author Share Posted May 13, 2007 also can someone help me out with the content thing for javascript posted on top(for content)? I dont know exactly what to change Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-252010 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 In your menu, your links haven't pasted right. Do you have a link to where this is online please? Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-252015 Share on other sites More sharing options...
tushar707 Posted May 13, 2007 Author Share Posted May 13, 2007 no. I dont have the website up yet. so I dont have it online. I am so confused now. :'( I have edited it a little bit: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Suckerfish Dropdowns - Vertical</title> <style type="text/css"> body { font-family: VladimirScrD; font-size: 24px; } #nav, #nav ul { /* all lists */ padding: 0; margin: 0; list-style: none; float : left; width : 149px; } #nav li { /* all list items */ position : relative; float : left; line-height : 29px; margin-bottom : -1px; width: 144px; } #nav li ul { /* second-level lists */ position : absolute; left: -999em; margin-left : 144px; margin-top : -1.20em; } #nav li ul ul { /* third-and-above-level lists */ left: -999em; margin-top : -29px; } #nav li a { width: 5em; w\idth : 5em; display : block; color : #1463a5; font-weight : 300; text-decoration : none; border : none; background-image: url(images/button.jpg); padding-top: 0; padding-right: 0em; padding-bottom: 0; padding-left: 1em; } #nav li a:hover { color : white; background : url(images/button_rollover.jpg); } #nav li:hover ul ul, #nav li:hover ul ul ul, #nav li.sfhover ul ul, #nav li.sfhover ul ul ul { left: -999em; } #nav li:hover ul, #nav li li:hover ul, #nav li li li:hover ul, #nav li.sfhover ul, #nav li li.sfhover ul, #nav li li li.sfhover ul { /* lists nested under hovered list items */ left: auto; } #content { margin-left : 6em; } </style> <script type="text/javascript"><!--//--><![CDATA[//><!-- sfHover = function() { var sfEls = document.getElementById("nav").getElementsByTagName("LI"); for (var i=0; i<sfEls.length; i++) { sfEls.onmouseover=function() { this.className+=" sfhover"; } sfEls.onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); } } } if (window.attachEvent) window.attachEvent("onload", sfHover); //--><!]]></script> </head> <body> <ul id="nav"> <li><a href="#">Home</a> </li> <li><a href="#">Our Programs</a> <ul> <li><a href="#">Climbing perches</a></li> <li><a href="#">Labyrinthfishes</a></li> <li><a href="#">Kissing gouramis</a></li> <li><a href="#">Pike-heads</a></li> <li><a href="#">Giant gouramis</a></li> </ul> </li> <li><a href="#">Resources</a> <ul> <li><a href="#">My Articles</a></li> <li><a href="#">Newsletters</a></li> <li><a href="#">Useful Links</a></li> </ul> </li> <li><a href="#">Events</a> <ul> <li><a href="#">Burrowing gobies</a></li> <li><a href="#">Dartfishes</a></li> <li><a href="#">Eellike gobies</a></li> <li><a href="#">Gobies</a></li> </ul> </li> <li><a href="#">Testimonials</a></li> <li><a href="#">About Me </a></li> <li><a href="#">Contact Us </a> </li> </ul> <p> </p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-252017 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 Judging by what I see your links are in the format of <a href="#">, is that correct? No onClick or anything? How does it know where to go when the links are clicked? Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-252019 Share on other sites More sharing options...
tushar707 Posted May 13, 2007 Author Share Posted May 13, 2007 well I have not put any links yet. What I wan to do is have a php include for the menu on the index. have it so when the someone clicks on a link, the content is the only that changes (towards the right of the menu). I dont want to whole page to load again. I dont know how to do that so content is the only thing that loads again (Posted the question in the same post). Do you know how to help me with both problems? Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-252021 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Page title</title> <style type="text/css"> body { font-family: VladimirScrD; font-size: 24px; } #nav, #nav ul { /* all lists */ padding: 0; margin: 0; list-style: none; float : left; width : 149px; } #nav li { /* all list items */ position : relative; float : left; line-height : 29px; margin-bottom : -1px; width: 144px; } #nav li ul { /* second-level lists */ position : absolute; left: -999em; margin-left : 144px; margin-top : -1.20em; } #nav li ul ul { /* third-and-above-level lists */ left: -999em; margin-top : -29px; } #nav li a { width: 5em; w\idth : 5em; display : block; color : #1463a5; font-weight : 300; text-decoration : none; border : none; background-image: url(images/button.jpg); padding-top: 0; padding-right: 0em; padding-bottom: 0; padding-left: 1em; } #nav li a:hover { color : white; background : url(images/button_rollover.jpg); } #nav li:hover ul ul, #nav li:hover ul ul ul, #nav li.sfhover ul ul, #nav li.sfhover ul ul ul { left: -999em; } #nav li:hover ul, #nav li li:hover ul, #nav li li li:hover ul, #nav li.sfhover ul, #nav li li.sfhover ul, #nav li li li.sfhover ul { /* lists nested under hovered list items */ left: auto; } #content { margin-left : 6em; } </style> <script type="text/javascript"><!--//--><![CDATA[//><!-- sfHover = function() { var sfEls = document.getElementById("nav").getElementsByTagName("LI"); for (var i=0; i<sfEls.length; i++) { sfEls.onmouseover=function() { this.className+=" sfhover"; } sfEls.onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); } } } if (window.attachEvent) window.attachEvent("onload", sfHover); //--><!]]></script> </head> <body> <?php include("menu.php"); ?> <div id="content" name="content">Default value</div> </body> </html> menu.php <ul id="nav"> <li><a href="#" onclick="document.getElementById('content').innerHTML = 'This is the homepage.';">Home</a> </li> <li><a href="#" onclick="document.getElementById('content').innerHTML = 'This is the our programs page.';">Our Programs</a> <ul> <li><a href="#">Climbing perches</a></li> <li><a href="#">Labyrinthfishes</a></li> <li><a href="#">Kissing gouramis</a></li> <li><a href="#">Pike-heads</a></li> <li><a href="#">Giant gouramis</a></li> </ul> </li> <li><a href="#">Resources</a> <ul> <li><a href="#">My Articles</a></li> <li><a href="#">Newsletters</a></li> <li><a href="#">Useful Links</a></li> </ul> </li> <li><a href="#">Events</a> <ul> <li><a href="#">Burrowing gobies</a></li> <li><a href="#">Dartfishes</a></li> <li><a href="#">Eellike gobies</a></li> <li><a href="#">Gobies</a></li> </ul> </li> <li><a href="#">Testimonials</a></li> <li><a href="#">About Me </a></li> <li><a href="#">Contact Us </a> </li> </ul> <p> </p> Notes Do all the links in menu.php like I have done the first two. In index.php the div there will contain the pages, you can style it as required. You will also have to upload your files or install PHP locally to test this. Chigley Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-252022 Share on other sites More sharing options...
tushar707 Posted May 13, 2007 Author Share Posted May 13, 2007 thanks a lot for the help! so this will solve both my problems? Also I am a little confused by this "In index.php the div there will contain the pages, you can style it as required. You will also have to upload your files or install PHP locally to test this." Like how do i add the content so it is the only thing that will change when i click on a link. I am sorry if i sound stupid. Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-252025 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 Look at the links on menu.php: onclick="document.getElementById('content').innerHTML = 'CODE HERE FOR PAGE TO BE DISPLAYED IN CONTENT DIV';" Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-252027 Share on other sites More sharing options...
tushar707 Posted May 13, 2007 Author Share Posted May 13, 2007 so I can type in anything there? anything in html and etc? that is so cool! also can i delete "default value" from "<div id="content" name="content">Default value</div>" one last thing. because you split the css from the links, when i do php include will the links know that a css is attached to it? So it doesn't show up. you are awesome. Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-252029 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 Yes you're right. You can use HTML in the onclick command, just go careful with the quotes Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-252034 Share on other sites More sharing options...
tushar707 Posted May 13, 2007 Author Share Posted May 13, 2007 one last thing. because you split the css from the links, when i do php include will the links know that a css is attached to it? and i can delete "default value" from the div code so it doesn't show up? Lastly, on index.php I have template. can I just save that as php instead of html and everything will flow fine? Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-252035 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 Yes you can get rid of the default value. In your template, put <div id="content" name="content"></div> where you want the content to be displayed. The page can be left as .html. The CSS is fine, and your menu will work perfectly Quote Link to comment https://forums.phpfreaks.com/topic/51140-solved-php-inlcude/#findComment-252046 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.