Huge sites with thousands of pages and the design hardcoded on each page, this might not be so common these days. But they still exist on some sites on the net. However today people have recognized how inefficient this really is and instead use solutions like dynamically built pages on the fly using PHP and MySQL.
A good solution but this doesn’t work for everyone, some still need to use the old fashion way.
Now think of a company that has a site with thousands of pages and they decide to perform a design change, I don’t know about you but I sure as hell wouldn’t want to get assigned to manually alter hundreds of pages.
And I’m pretty sure most companies don’t like it as well as it’s very time consuming and inefficient, this means the price will be high for this types of changes.
However there are some alternatives of having thousand of hardcoded pages, by taking out the html code outside the pages itself, so when a redesign is needed all that has to be changed will be one file.
For this purpose I’ve created a PHP class as an example that you can look at to get the idea of how this would work.
class Site {
//Site class attributes
public content;
public title = ‘Mysite.com Where you\’ll find yadayada’;
public keywords = ‘I love search engines’;
public buttons = array(‘Home’ => ‘home.php’,
‘Something’ => ’some.php’,
‘Contact’ => ‘contact.php’
);
public function __set($name, $value){
$this->$name = $value;
}
publiv function Display(){
echo “<html>\n<head>\n“;
$this->DisplayTitle();
$this->DisplayKeywords();
$this->DisplayCSS();
echo “</head>\n<body>\n“;
$this->DisplayHeader();
$this->DisplayMeny($this->buttons);
echo $this->content;
$this-> DisplayFooter();
echo “</body>\n</html>\n“;
}
public function DisplayTitle(){
echo ‘<title>’.$this->title.‘</title>’;
}
public function DisplayKeywords(){
echo “<meta name=\”keywords\” content=\”“..htmlentities($this->keywords).“\” \>“;
}
public function DisplayCSS(){
?>
<styles>
<!–
Put your css code here.
–>
</styles>
<?php
}
public function DisplayHeader(){
//Put the html code for the header here
}
public function DisplayMenu($buttons){
echo “<table width=’100%’ cellpadding=’4′ cellspacing=’4′>\n“;
echo “<tr>\n“;
//calculate button size
$width = 100 / count($buttons);
foreach ($buttons as $name=>$url){
$this->DisplayButton($width, $name, $url, !$this->isUrlCurrentPage($url));
}
echo “</tr>\n“;
echo “</table>\n“;
}
public function isUrlCurrentPage($url){
if(strpos($_SERVER[‘PHP_SELF’], $url) == false){
return false;
}
else{
return true;
}
}
public function DisplayButtons($width, $name, $url, $active=true){
if($active)
{
echo “<td width=’”.htmlentities($width).“%’><a href=’”.htmlentities($url).“‘><span>$name</span></a></td>”;
}
else{
echo “<td width=’”.htmlentities($width).“%’><span>$name</span></td>”;
}
}
public function DisplayFooter()
{
?>
<!– Put the footer html here –>
<?php
}
}
?>
That’s the class that holds the design for all the pages on the site.
Instead of having the html hardcoded on each and every page we simply call the class in the pages which will produce flexibility when we need to change or add elements.
Now how do you use this, look at the code below to see how easily this is added to the pages.
require_once(’site.class’);
$page = new Site();
$page->content = ‘<p>Here goes the content of the site yada yada.
Could even be displayed from the MySQL server.’;
$page->Display();
?>
As you see producing new pages takes very little work, however this means that the pages must be very similar. However you have the possibility to create a site2.class with the changes.
Let say you have 4 different pages designs that you practically use throughout the site, and then four classes would do the job and still make the job easier.
You could even have a primary class which has all of the elements that are the same for every page, usually this means header and footer.
Then create child classes that inherit from the mother class and you override or add elements in the child classes that are different.
How you work this out is all up to you, just find the best method that works for you. Beneath I created a child class that has one row more in the menu.
require_once(’site.class’);
class SubSite extends Site{
private $secondRowButtons = array( ‘Contact webmaster’ => ‘con.php=webm’,
‘Contact support’ => ‘con.php=supp’,
‘Contact owner’ => ‘con.php=ownr’
);
public function Display(){
echo “<html>\n<head>”;
$this->DisplayTitle();
$this->DisplayKeywords();
$this->DisplayCSS();
echo “</head>\n<body>\n“;
$this->DisplayHeader();
$this->DisplayMenu($this->buttons);
$this->DipslayMeny($this->secondRowButtons);
echo $this->content;
$this->DisplayFotter();
echo “</body>\n</html>\n“;
}
}
$subsite = new SubSite();
$subsite->Content = ‘Yada Yada’;
$subsite->Display();
?>
I hope this gave some ideas on how to create more manageable pages on your sites.










Leave a Reply