Need a new web host or having a problem with a script? Tips and advice on the best way to design, build and maintain your most valuable asset - your website!

PHP menu?

laterales
Posts: 40
Joined: 17 Nov 06
Trust:

PHP menu?

Hey everyone :D

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!
  • 1
Site Admin
markling
Posts: 2071
Joined: 13 Jun 06
Trust:
Hey laterales,

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
  • 1
Limited time special - Pathway to Passive for $37: https://www.affilorama.com/pathwaytopassive
 
PremiumMember
chatyak86
Posts: 1085
Joined: 17 Jun 06
Trust:
You need 2 files.

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.
  • 1
laterales
Posts: 40
Joined: 17 Nov 06
Trust:
Thanks Mark, I will definitely read that update.

That's exactly what I needed Adrian, thanks so much, that's legendary.

Cheers!
  • 1
laterales
Posts: 40
Joined: 17 Nov 06
Trust:
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!
  • 1
PremiumMember
sean06
Posts: 1004
Joined: 16 Jun 06
Trust:
I added sites from all over the shop with one of my sites and it didn't affect me at all. I'm on the first page for a very competitive search term.

Will this change in time? Yeh I'm sure it will, you are still better off focusing on good quality links.
  • 1
www.SixDayWeekend.com
Free Training Videos reveal how I make 6 figures while travelling the world
 
PremiumMember
chatyak86
Posts: 1085
Joined: 17 Jun 06
Trust:
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,
  • 1
laterales
Posts: 40
Joined: 17 Nov 06
Trust:
Great, thanks once again Adrian and Sean, excellent stuff. :D
  • 1
stevenar
Posts: 63
Joined: 18 Apr 07
Trust:
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
  • 1
PremiumMember
sean06
Posts: 1004
Joined: 16 Jun 06
Trust:
I've gotten this error before too. Usually it's on one of my subdirectory pages and I've forgotten to change it from /navigation.php to www.yoursite.com/navigation.php.

Try that and let me know if it still doesn't work.
  • 1
www.SixDayWeekend.com
Free Training Videos reveal how I make 6 figures while travelling the world
 
PremiumMember
chatyak86
Posts: 1085
Joined: 17 Jun 06
Trust:
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"
  • 1
stevenar
Posts: 63
Joined: 18 Apr 07
Trust:
the index.php and the navagation.php are both in the same folder . Not sure whats wrong :(
  • 1
PremiumMember
chatyak86
Posts: 1085
Joined: 17 Jun 06
Trust:
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
  • 1
stevenar
Posts: 63
Joined: 18 Apr 07
Trust:
I knew you were gunna say that. I should of said that in my last post :P.

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.
  • 1
PremiumMember
chatyak86
Posts: 1085
Joined: 17 Jun 06
Trust:
Hmm not sure... take screenshots of your code on the page and of the folder view and post them here.
  • 1
Site Admin
markling
Posts: 2071
Joined: 13 Jun 06
Trust:
That error means that it can't find your navigation file.

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
  • 1
Limited time special - Pathway to Passive for $37: https://www.affilorama.com/pathwaytopassive
 
stevenar
Posts: 63
Joined: 18 Apr 07
Trust:
ah crap. That was the problem. hahaha.

Thank You Mark :oops:
  • 1
laterales
Posts: 40
Joined: 17 Nov 06
Trust:
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!
  • 1
stevenar
Posts: 63
Joined: 18 Apr 07
Trust:
If you're using Dreamweaver you can just open all your pages and hit CTRL+F .
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.
  • 1
PremiumMember
chatyak86
Posts: 1085
Joined: 17 Jun 06
Trust:
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:
  • 1
laterales
Posts: 40
Joined: 17 Nov 06
Trust:
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!
  • 1
Last edited by sydney on 03 Jun 10 4:10 am, edited 1 time in total.
Reason: sample links
 

laterales
Posts: 40
Joined: 17 Nov 06
Trust:
Oh, we posted at the same time Adrian!
  • 1
PremiumMember
chatyak86
Posts: 1085
Joined: 17 Jun 06
Trust:
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.
  • 1
PremiumMember
chatyak86
Posts: 1085
Joined: 17 Jun 06
Trust:
laterales wrote:Oh, we posted at the same time Adrian!


We are in sync :lol:
  • 1
laterales
Posts: 40
Joined: 17 Nov 06
Trust:
We are, I was hoping you were around!

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!
  • 1