...

View Full Version : Server Side Includes



rickfink
12-07-2009, 06:36 PM
Trying to implement Server Side Includes into my site, I have a sidebar on every page and want to just edit one and every one will update. I think Example 2 on here (http://www.w3schools.com/PHP/php_includes.asp) is what I want to use, but how do I keep the same formatting so it looks the same?

Site: www.baysidesuperior.org
Sidebar Code:

<div id="search-news2">

<h2 class="downcast">Sermons</h2>

<div id="sermons">
<p><a href="javascript:november2909()">November 29, 2009</a></p>

<p><a href="javascript:november2209()">November 22, 2009</a></p>

<p><a href="javascript:november1509()">November 15, 2009</a></p>

<p class="more"><a href="media">more</a></p>

</div>

<h2 class="downcast">Upcoming Events</h2>

<div id="news">

<p>Dec 04</p>
<h3><a href="events#E1">Senior Adults' Banquet</a></h3>

<p>Dec 05</p>
<h3><a href="events#E2">Chancellors Concert</a></h3>

<p>Dec 06</p>
<h3><a href="events#E3">Christmas Program</a></h3>

<p>Dec 12</p>
<h3><a href="events#E4">White Elephant Party</a></h3>

<p>Dec 24</p>
<h3><a href="events#E5">Christmas Eve Service</a></h3>

</div>
</div>

sidebar CSS:

#search-news {
float: right;
width: 208px;
}

#search-news div {
margin: 0;
padding-top: 3px;
padding-right: 0;
padding-bottom: 3px;
padding-left: 0;
}

#search-news2 {
float: right;
width: 140px;
}

#search-news2 div {
margin: 0;
padding-top: 3px;
padding-right: 0;
padding-bottom: 3px;
padding-left: 0;
}

#search-news2 #q {
width: 140px;
border: 1px solid #859D31;
}

#search-news2 .downcast {
background: #E6E7E7;
border-top: 1px solid #CFD0D0;
padding: 3px 4px 4px 4px;
margin: 2px 0 0 0;
font-weight: bold;
}

#search-news2 h3 {
background: url(images/bullet_letter.gif) no-repeat;
padding-left: 15px;
font-weight: bold;
margin-right: 0;
margin-bottom: .5em;
margin-left: 0;
}

#search-news2 p {
padding-left: 15px;
padding-right: 2px;
margin-top: 0.1em;
margin-right: 0;
margin-bottom: 0.1em;
margin-left: 0;
font-size: 10px;
}

#search-news div ul { float: left; }

#search-news div li {
float: right;
border-bottom: 1px solid #e9e9e9;
width: 192px;
margin-top: 0;
margin-right: 0;
margin-bottom: 7px;
margin-left: 0;
padding-top: 0;
padding-right: 0;
padding-bottom: 6px;
padding-left: 0px;
}

#search-news div li a {
font-weight: bold;
text-transform: none;
display: block;
margin-top: -12px;
margin-right: 0;
margin-bottom: 0;
margin-left: 50px;
}

#search-news #q {
width: 140px;
border: 1px solid #859D31;
}

#search-news .downcast {
background: #E6E7E7;
border-top: 1px solid #CFD0D0;
padding: 3px 4px 4px 4px;
margin: 2px 0 0 0;
font-weight: bold;
}

#search-news h3 {
background: url(images/bullet_letter.gif) no-repeat;
padding-left: 15px;
font-weight: bold;
margin-right: 0;
margin-bottom: .5em;
margin-left: 0;
}

#search-news p {
padding-left: 15px;
padding-right: 2px;
margin-top: 0.1em;
margin-right: 0;
margin-bottom: 0.1em;
margin-left: 0;
font-size: 10px;
}

Excavator
12-07-2009, 07:16 PM
Hello rickfink,
All you need to change is the content of #search-news.

It will be something like this, on all pages:
<div id="search-news">
<?php include("sidebar.php"); ?>
</div>


Your sidebar php should read like this -
<h2 class="downcast">Sermons</h2>

<div id="sermons">
<p><a href="javascript:november2909()">November 29, 2009</a></p>

<p><a href="javascript:november2209()">November 22, 2009</a></p>

<p><a href="javascript:november1509()">November 15, 2009</a></p>

<p class="more"><a href="media">more</a></p>

</div>

<h2 class="downcast">Upcoming Events</h2>

<div id="news">

<p>Dec 04</p>
<h3><a href="events#E1">Senior Adults' Banquet</a></h3>

<p>Dec 05</p>
<h3><a href="events#E2">Chancellors Concert</a></h3>

<p>Dec 06</p>
<h3><a href="events#E3">Christmas Program</a></h3>

<p>Dec 12</p>
<h3><a href="events#E4">White Elephant Party</a></h3>

<p>Dec 24</p>
<h3><a href="events#E5">Christmas Eve Service</a></h3>

</div>


And it will get it's styling from the CSS the same as it always did so it will look just like it does now.

rickfink
12-07-2009, 07:33 PM
Do I need to put anything else in the php file? Or just exactly what you put there. No other code in the beginning or anything?

Just wondering because it didn't work for me

www.baysidesuperior.org/events1

Excavator
12-07-2009, 08:07 PM
It looks like your events page still has an .hmtl extension.
Any page that uses your include will need to be renamed with a .php extension.
Also, just to make sure, you've verified your server is running php and it's available to you?

Maybe this is an easier tutorial for building a php include. (http://www.tizag.com/phpT/include.php)

weaver
12-07-2009, 10:41 PM
The messages above use php for includes. If you do not wish to use php, you can use a server side includes that does not require php. You can follow this tutorial to write your server side includes: http://wiki.lunarpages.com/Easier_Way_to_Edit_Static_Content_Using_SSI.

This says you then need to save your files as shtml. However, you can have each html page parsed as shtml. This requires you to edit your htaccess file as shown in this tutorial. http://wiki.lunarpages.com/SSI_on_html_Web_Pages.

Your included file need only have the text you want included. do not put in <head> tags, etc.

This is just another way of doing it if you want to retain your pages with the .html extensions.

Weaver

rickfink
12-08-2009, 01:21 AM
I changed all the extensions to .php, works great now! Thanks!

rickfink
12-09-2009, 06:05 PM
Is there a performance hit when using this method?

Doesn't seem like there is but because I have many pages I am using this method on my drop down menu, footer, and sidebar so just wondering.

_Aerospace_Eng_
12-09-2009, 06:11 PM
No its fine. Its the standard.

hadfirrag
12-10-2009, 01:00 AM
Here is, in my opinion, the most interesting part:
Sedebar Code:

//If first time key in date run statement
if(first == 0){
++first;//Track if is the first record key in
items[i] = new Item(itemNumber, itemDesc, sellPrice, quantity);
}
//Else continue key in record
else{
entries = items[0].getEntries();//Get number of entries entered
for(j=0; j<entries; ++j){

duplicate = items[j].equals(itemNumber, itemDesc, sellPrice, quantity);//Check for duplication of entries

if(duplicate == true) {
Print.duplicateError();
--i;
--looping;
break;
}
}
if(duplicate == false)//else save record
items[entries] = new Item(itemNumber, itemDesc, sellPrice, quantity);
}
__________________________
Courtier conseil financement immobilier achat | (http://**************************/)Demande credit simulation plan de financement immobilier | (http://**************************/)Calcul pret projet financement immobilier travaux (http://**************************/)

Excavator
12-10-2009, 01:35 AM
That "interesting part" crap is starting to become annoying. :mad:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum