PHP menu?
-
laterales
- Posts: 48
- Joined: 17 Nov 06
- Location: QLD, Australia
- Trust:
26 Apr 07 12:50 am
I read a post a while back that Sean started, about setting up a menu in PHP so that you only have to include some text and update that, rather than have to change every page when you add to your site.
Sean did you have any luck with that?
Does anyone know of a (preferably free) guide to setting that up? Or has anyone got any ideas of what I can do so that every time I add a page to my site I only need to change one page? I am completely self taught when it comes to web design (it probably shows) so it needs to be fairly clearly explained.
Thanks!
-
markling - Posts: 2344
- Joined: 13 Jun 06
- Trust:
26 Apr 07 1:53 am
We wrote a big article on this in the February Affilorama Update magazine, in the "Ask A Geek" section. It also talks about using PHP includes to silo your site. That should give you a good place to start.
Regards,
Mark
-
adrian - Posts: 1420
- Joined: 17 Jun 06
- Location: Canada
- Trust:
26 Apr 07 2:01 am
Your HTML pages and your menu page.
1) Copy the menu code you have now (the html part) and paste that into a completely blank page.
2) Save that blank page as navigation.inc
3) Where your menu was in your HTML page.... delete all of that code.
4) In its place.... put this....
<?php include("navigation.inc"); ?>
5) Save the page as .php
6) Now all you have to do is put that 1 line of php code into any php page where you want your menu to appear.... when you need to update the menu for the entire site... simply change the code in the navigation.inc file.
PS: Keep in mind if you have folders and subfolders and pages of different levels in your site... you cannot simply use <?php include("navigation.inc"); ?> because it won't be able to find the file. What I suggest is to do this...
<?php include("http://www.mysitehere.com/navigation.inc"); ?>
Now it will read it on any page.
-
laterales
- Posts: 48
- Joined: 17 Nov 06
- Location: QLD, Australia
- Trust:
26 Apr 07 7:10 am
That's exactly what I needed Adrian, thanks so much, that's legendary.
Cheers!
-
laterales
- Posts: 48
- Joined: 17 Nov 06
- Location: QLD, Australia
- Trust:
27 Apr 07 5:25 am
I signed up to the link in your sig, but on the first day I got 8 requests and from what I can tell, they are fairly crap. Just pages with loads of links that are quite obviously link farmish. I'm worried that they are linking to me at all, let alone link back to them. I'm paranoid that Google may think that this is an obvious link exchange for ranking purposes (with good reason) or do they not worry about this so much anymore?
What kind of links do you accept? Would it be normal for me to reject the first 8 I get, because I really only want to link to sites that would be of interest to my visitors? Or do you have a seperate page for link partners of this kind?
Any thoughts would be great.
Cheers!
-
sean06 - Posts: 1401
- Joined: 16 Jun 06
- Location: Australia
- Trust:
27 Apr 07 1:17 pm
Will this change in time? Yeh I'm sure it will, you are still better off focusing on good quality links.
-
adrian - Posts: 1420
- Joined: 17 Jun 06
- Location: Canada
- Trust:
27 Apr 07 1:20 pm
laterales wrote:Hey Adrian, one more question, sorry to keep bothering you. :roll:
I signed up to the link in your sig, but on the first day I got 8 requests and from what I can tell, they are fairly crap. Just pages with loads of links that are quite obviously link farmish. I'm worried that they are linking to me at all, let alone link back to them. I'm paranoid that Google may think that this is an obvious link exchange for ranking purposes (with good reason) or do they not worry about this so much anymore?
What kind of links do you accept? Would it be normal for me to reject the first 8 I get, because I really only want to link to sites that would be of interest to my visitors? Or do you have a seperate page for link partners of this kind?
Any thoughts would be great.
Cheers!
Hi laterales :)
No it should not affect you. I exchange links with any site that is family friendly AND indexed in Google. After you do that focus on getting a bunch of related links.
Link Market is also a good place to find those.
All the Best,
-
laterales
- Posts: 48
- Joined: 17 Nov 06
- Location: QLD, Australia
- Trust:
27 Apr 07 7:27 pm
-
stevenar
- Posts: 77
- Joined: 18 Apr 07
- Trust:
28 Apr 07 11:33 pm
Warning: main(navigation.php) [function.main]: failed to open stream: No such file or directory in /home/stevenar/public_html/index.php on line 34
Warning: main(navigation.php) [function.main]: failed to open stream: No such file or directory in /home/stevenar/public_html/index.php on line 34
Warning: main(navigation.php) [function.main]: failed to open stream: No such file or directory in /home/stevenar/public_html/index.php on line 34
Warning: main() [function.include]: Failed opening 'navigation.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/stevenar/public_html/index.php on line 34
-
sean06 - Posts: 1401
- Joined: 16 Jun 06
- Location: Australia
- Trust:
29 Apr 07 12:51 am
Try that and let me know if it still doesn't work.
-
adrian - Posts: 1420
- Joined: 17 Jun 06
- Location: Canada
- Trust:
29 Apr 07 1:17 am
stevenar wrote:I tried that include stuff and followed the directions in the "Ask a Geek" section. I uploaded the files and when i checked it out it says.
Warning: main(navigation.php) [function.main]: failed to open stream: No such file or directory in /home/stevenar/public_html/index.php on line 34
Warning: main(navigation.php) [function.main]: failed to open stream: No such file or directory in /home/stevenar/public_html/index.php on line 34
Warning: main(navigation.php) [function.main]: failed to open stream: No such file or directory in /home/stevenar/public_html/index.php on line 34
Warning: main() [function.include]: Failed opening 'navigation.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/stevenar/public_html/index.php on line 34
Your page must be in a subfolder then.
If it is change the "navigation.inc" to "../navigation.inc"
-
stevenar
- Posts: 77
- Joined: 18 Apr 07
- Trust:
29 Apr 07 1:23 am
-
adrian - Posts: 1420
- Joined: 17 Jun 06
- Location: Canada
- Trust:
29 Apr 07 2:20 am
stevenar wrote:the index.php and the navagation.php are both in the same folder . Not sure whats wrong :(
It shouldn't be navigation.php
It should be navigation.inc
-
stevenar
- Posts: 77
- Joined: 18 Apr 07
- Trust:
29 Apr 07 2:59 am
I tried .inc too. I read your post above and tried that first. Then I saw marks post and checked out the "Ask a Geek" section. He uses navagation.php in the example and yes.. I am pointing the include code, thats in my index.php, to navagation.php.
-
adrian - Posts: 1420
- Joined: 17 Jun 06
- Location: Canada
- Trust:
29 Apr 07 3:01 am
-
markling - Posts: 2344
- Joined: 13 Jun 06
- Trust:
29 Apr 07 11:07 pm
Try changing the include to this:
include('/home/stevenar/public_html/navigation.php');
And see if it can find it.
My only other suggestion is that you've miss-spelled "navigation" (I notice you're spelling it "navagation" in this post) or you have capital letters in the file name.
But that's definitely a "can't find the file" error.
Regards,
Mark
-
stevenar
- Posts: 77
- Joined: 18 Apr 07
- Trust:
30 Apr 07 3:31 am
Thank You Mark :oops:
-
laterales
- Posts: 48
- Joined: 17 Nov 06
- Location: QLD, Australia
- Trust:
30 Apr 07 9:09 pm
There is one thing now, as I am converting an existing site, all the links in all the pages point to .html pages. Am I going to have to change all the links to .php pages (a daunting task) and resave all of the pages with the navigation.inc menu in them as php, or is there an easier way?
I tried to look this up in the ask a geek section, went to the February update and couldn't seem to find it, certainly not to say that it isn't there!
Thanks again, you guys are lifesavers!
-
stevenar
- Posts: 77
- Joined: 18 Apr 07
- Trust:
30 Apr 07 9:31 pm
A menu will pop up.
In the "Find" box put .html
In the "Replace" box put .php
Now pick a page and push CTRL+F. Click on "Replace All". "Save as" your page from pagename.html to pagename.php.
Rinse and repeat. Took me about 3 minutes to change all the .html links within my page to .php's and save all my pages with the php extension.
-
adrian - Posts: 1420
- Joined: 17 Jun 06
- Location: Canada
- Trust:
30 Apr 07 9:57 pm
laterales wrote:Hey guys, just having a go at the navigation.inc menu. All seems to be going well - at least on the index page!
There is one thing now, as I am converting an existing site, all the links in all the pages point to .html pages. Am I going to have to change all the links to .php pages (a daunting task) and resave all of the pages with the navigation.inc menu in them as php, or is there an easier way?
I tried to look this up in the ask a geek section, went to the February update and couldn't seem to find it, certainly not to say that it isn't there!
Thanks again, you guys are lifesavers!
If your host uses an apache server you can do this.
Open notepad and create a file called this... exactly like this....
.htaccess
In that file put this one line of code... just like this....
AddType application/x-httpd-php .html
This will allow you to run PHP on any HTML page
:wink:
-
laterales
- Posts: 48
- Joined: 17 Nov 06
- Location: QLD, Australia
- Trust:
30 Apr 07 9:58 pm
I am having a go at adding this line of code to my .htaccess file, so now it looks like this:
ErrorDocument 404 "http://www.mysite.com/error404.htm"
AddType application/x-httpd-php .html .htm
Have I got that right? Would this mean that the pages should now get parsed as html, so I wouldn't mean to change them?
Becauuuuse, now, not even my error page is working. When I click on home, which obviously is "http://www.mysite.com/index.html" - I get a normal error page error. Have I written that code in right, or does it need to be seperated somehow? I have uploaded in ascii, CHMOD 644.
Any help would be great, or should I just change everything to .php?
Cheers!
-
laterales
- Posts: 48
- Joined: 17 Nov 06
- Location: QLD, Australia
- Trust:
30 Apr 07 10:00 pm
-
adrian - Posts: 1420
- Joined: 17 Jun 06
- Location: Canada
- Trust:
30 Apr 07 10:03 pm
laterales wrote:Cool! Thanks for that! I will do that if I do need to change them all.
I am having a go at adding this line of code to my .htaccess file, so now it looks like this:
ErrorDocument 404 "http://www.mysite.com/error404.htm"
AddType application/x-httpd-php .html .htm
Have I got that right? Would this mean that the pages should now get parsed as html, so I wouldn't mean to change them?
Becauuuuse, now, not even my error page is working. When I click on home, which obviously is "http://www.mysite.com/index.html" - I get a normal error page error. Have I written that code in right, or does it need to be seperated somehow? I have uploaded in ascii, CHMOD 644.
Any help would be great, or should I just change everything to .php?
Cheers!
Are your pages .html or .htm?
You could try this...
AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
As for the other thing in your .htaccess............... I am not sure.
All I have in my .htaccess is one or both of those lines above.
-
adrian - Posts: 1420
- Joined: 17 Jun 06
- Location: Canada
- Trust:
30 Apr 07 10:04 pm
laterales wrote:Oh, we posted at the same time Adrian!
We are in sync :lol:
-
laterales
- Posts: 48
- Joined: 17 Nov 06
- Location: QLD, Australia
- Trust:
30 Apr 07 10:38 pm
Well, I've given up on the .htaccess thing. I took the other code out and my error page starting working fine again, so might be a server thing? No idea. I want to add a comment script to my articles anyway so it's no big deal.
I was reading in the forum that I found it that the one person who could get it to work was with HostGator, so Sean might be fine.
Thanks!
