/    Sign up×
Community /Pin to ProfileBookmark

php include help

I’m trying to create an include in order to make a global template for my link changes.

I have a file with my menu links on it called menu.php.

My question is this:
do I have to put the php include in the index.html just as I would for an external style sheet?

or do I create a separate index.php? and do I make the index.php my template?

I hope I’m asking this right. thanks.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@donatelloMay 03.2010 — You can do it any way you like, however if it is a new site without any page rank and/or traffic, I would use PHP include in your index file named: index.php

To make PHP run in an HTML file, or one with the name index.html, you would need to modify your .htaccess file.

If you want to speed things up, just install Wordpress and create your own theme... then you get an entire CMS instead of re-inventing the wheel... so to speak...

?
Copy linkTweet thisAlerts:
@jefitoauthorMay 03.2010 — Thanks, I'll give it a try.
Copy linkTweet thisAlerts:
@SrWebDeveloperMay 03.2010 — In most setups PHP commands can only be put in files with the .php extension. So if you wish to include menu.php in your startup page, rename index.html to index.php and add the include statement to it where you want the menu to appear.

Generally, include all templates, classes and function scripts within index.php. Take time to plan on which files will be included or not in certain situations and add the highest level if/then/else or switches in index.php used to determine those situations. To each their own, this is not a rule but merely a suggestion if you're building it from scratch.

Keeps things organized and efficient, plus using index.php as the default loading script means visitors can go to www.yourdomain.com and get your home page. Or, any others as you modify the URL's from there.

-jim
Copy linkTweet thisAlerts:
@SrWebDeveloperMay 03.2010 — To make PHP run in an HTML file, or one with the name index.html, you would need to modify your .htaccess file.[/quote]

I strongly discourage this. The server will parse every single HTML page even if no PHP code exists and noticeably hog valuable resources, among other reasons. It's okay to suggest this to users so long as you also add this obvious and important disclaimer, too! Yes I am aware you said .htaccess and it will only affect files there, but we're talking index.php in this topic which means placing it in the document root (i.e. it affects the entire site) :p

-jim

ps: I posted my original response without knowing you posted yours, FYI.
×

Success!

Help @jefito spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 12.1,
social: @webDeveloperHQ,
});

legal: ({
terms: of use,
privacy: policy
analytics: Fullres
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: Anonymous,
tipped: article
amount: 1000 SATS,

tipper: @aldoushuxley,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 1000 SATS,
)...