Advanced Web Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsWeb DesignAdvanced Web Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 26th, 2007, 03:58 AM
JayJ JayJ is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 13 JayJ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 8 m 15 sec
Reputation Power: 0
Inserting HTML Into A Page?

Hi all,

I have a problem, and I'm wondering if there's a practical solution to it...

I want to insert an HTML page into an existing HTML page. I want to insert a list of recent article links into every page of my website, without having to cut and paste the code directly onto every page, every single week.

Is there a way to tell my pages to insert a block of HTML code from an "article links" file?

The only idea I have is that I could code the HTML links code into a PHP file, and then get my pages to call run PHP file everytime a page is loaded. But I have no idea what function I would use.

Any suggestions?

Reply With Quote
  #2  
Old February 26th, 2007, 09:45 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
If your server supports PHP, the easiest solution would be to create a separate file. Name the file something like 'links.htm' and paste in the HTML code you want on every page.

On the main page, use <?php include('links.htm'); ?> to include the external file. Make sure your main page is named .php so your server will run it through the PHP interpretor.

You might find PHP's documentation of include() helpful.
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter!
DevArticles Forum Moderator

"The net is a waste of time, and that's exactly what's right about it." -- William Gibson

Reply With Quote
  #3  
Old February 26th, 2007, 01:13 PM
JayJ JayJ is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 13 JayJ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 8 m 15 sec
Reputation Power: 0
Quote:
Originally Posted by MadCowDzz
Make sure your main page is named .php so your server will run it through the PHP interpretor.

Are you saying my main page should then be index.php? If I want to insert this code on every page in my website, would that also mean that every page would have to be a .php?

If so, I'm not sure I can work with that. Is there any other way? Is there a way where I can keep the .html, but still use php within it to do what I want?

Reply With Quote
  #4  
Old March 1st, 2007, 05:26 AM
Humanetainit's Avatar
Humanetainit Humanetainit is offline
Beyond help
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Location: The Netherlands
Posts: 223 Humanetainit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 32 m 30 sec
Reputation Power: 2
Quote:
Originally Posted by JayJ
Is there a way where I can keep the .html, but still use php within it to do what I want?
If you could create a .htaccess (no extension!) file, with this:
Code:
<FilesMatch "^index.html$">
ForceType application/x-httpd-php
</FilesMatch>
and put this in the root of your site, index.html will be parsed as php. Alternatively, you could remove 'index', so that all file ending in .html will be parsed. Don't do this unless you really want to parse them as php, it will make execution slower.

If used properly, there will be next to no code duplication with php.
__________________
One World... Humanetainit | Program secure

Last edited by Humanetainit : March 1st, 2007 at 05:29 AM.

Reply With Quote
  #5  
Old March 4th, 2007, 08:05 PM
JayJ JayJ is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 13 JayJ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 8 m 15 sec
Reputation Power: 0
Quote:
Originally Posted by Humanetainit
If you could create a .htaccess (no extension!) file, with this:
Code:
<FilesMatch "^index.html$">
ForceType application/x-httpd-php
</FilesMatch>
and put this in the root of your site, index.html will be parsed as php. Alternatively, you could remove 'index', so that all file ending in .html will be parsed. Don't do this unless you really want to parse them as php, it will make execution slower.

If used properly, there will be next to no code duplication with php.

Are there any other ways without using PHP?

Reply With Quote
  #6  
Old March 5th, 2007, 01:52 AM
Humanetainit's Avatar
Humanetainit Humanetainit is offline
Beyond help
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Location: The Netherlands
Posts: 223 Humanetainit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 32 m 30 sec
Reputation Power: 2
Yes, Server Side Includes, but your server has to support them.
Code:
<!--#include virtual="articlelinks.html" -->

Reply With Quote
  #7  
Old March 5th, 2007, 12:05 PM
JayJ JayJ is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 13 JayJ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 8 m 15 sec
Reputation Power: 0
Quote:
Originally Posted by Humanetainit
Yes, Server Side Includes, but your server has to support them.
Code:
<!--#include virtual="articlelinks.html" -->

Thanks a million! So simple, and it works for me.

Reply With Quote
  #8  
Old March 5th, 2007, 12:08 PM
Humanetainit's Avatar
Humanetainit Humanetainit is offline
Beyond help
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Location: The Netherlands
Posts: 223 Humanetainit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 32 m 30 sec
Reputation Power: 2
You're quite welcome!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsWeb DesignAdvanced Web Development > Inserting HTML Into A Page?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT