 |
 |
 |
 |
 |
| Author |
Message |
Saszoo

Joined: 07 Jun 2006 Posts: 409 Location: Norway |
|
Head first |
|
I'm sorry, but I couldn't stand for the temptation of being the first to post here
The code snippet I want to share is my usual head section. As we all know, all webpages starts with a head, and therefore I thought this could make for a first post. I'll just post the code, and then I'll explain afterwards:
 |  |
<?php
include 'path_to_cnr/head.php';
$Titles = array (
'search' => $search . " « Search for articles",
'archives' => "The exciting archive",
'registrer' => "Registrer yourself as a user now!",
);
$PageTitle = $Titles[$do];
if (!$PageTitle) {
$PageTitle = cn_title(' « ', true);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $PageTitle; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="description" content="<?=(!$_GET['title'] ? 'Some general information' : cn_meta('description'));?>" />
<meta name="keywords" content="<?=(!$_GET['title'] ? 'some, general, keywords' : cn_meta('keywords'));?>" />
<meta name="Author" content="Me" />
<meta name="Copyright" content="My company" />
<link rel="shortcut icon" href="http://www.domain.tld/favicon.ico">
<link rel="alternate" type="application/rss+xml" title="RSS" href="<?=cute_get_link(array(), 'feed', 'rss'); ?>" />
<link rel="stylesheet" title="Default" type="text/css" href="http://www.domain.tld/style.css" />
<!--[if lt IE 7]>
<script defer type="text/javascript" src="http://www.domain.tld/movement.js"></script>
<![endif]-->
</head> |
So why this approach?
First, let's break this code to pieces, making it easier to handle.
The first php-part has two functions.
1) it includes head.php which is essential, and
2) it collects the page titles from pages that are included from your main page. Example:
Your include code looks like this:
 |  |
<?php
if ($do == 'search'){
include $cutepath.'/search.php';
}
elseif ($do == 'archives'){
$template = 'Headlines';
include $cutepath.'/show_news.php';
}
elseif ($do == 'registrer') {
echo regForm('default');
}
$number = 6;
include $cutepath.'/show_news.php';
}
?> |
And you do not want the normal cn_title(' « ', true) to be the title for all of your included pages, for example for search, then this is one approach. Of course you could have added php-headers to the files that will be included, but that's your choice. The $search I have put infront of the search-title, makes so the searchword the user search for is turning up in the title aswell.
Next we have to specify what doctype we are using to ensure validity, fulfill the title, specify charset, add som metadescription and keywords. The way they are included by php makes so you can have keywords/description even though you are not in full story view. Following up is some information about your site, it's owners and so on, a favicon is a nice touch, making this more recognizeable, and of course RSS so the user can press the RSS-button in his browser, and the the filepath to your stylesheet. It's nice to have it external, cause inlinestyling makes for so much unneccesary work.
The last is something maybe not so useful, but I always have a file called movement.js where I put all my quirks and dirty hacks for IE only.
Finally I want to apollogize for my bad english, and my rudeness for writing the first post with some of FI-DD's snippets.
_________________ My cute.ru site |
|
| Thu Feb 01, 2007 8:18 pm |
|
 |
Guest
|
|
|
Please login to hide the ads.
|
|
|
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|
 |
 |
 |
|