Summary
This is a really simple snippet that allows you to have more controll over of a page's styling needs.
Usage
For example, let's say you want to assign a background color to specific pages - or - a different image per page (think rotating header images) somewhere on the page. This snippet will allow you to control that more easily and even give greater control traversing even deeper into the xhtml.
How it works
The snippet first looks to see if pathauto is installed. If so it does a query to the url_alias table to see if an alias has been created yet. If no result then it does a quick string replace to make a friendly name for an id or class.
The Snippet
Place the following at the top inside your page.tpl.php file:
<?php
if(module_exists('pathauto')) {
$result = db_query("SELECT dst FROM {url_alias} WHERE src='%s'", $_GET['q']);
if ($data = db_fetch_object($result)) {
$body_id = str_replace("/", "-", $data->dst);
}
}
else {
$body_id = str_replace(array('/', '_'), array('-', '-'), $_GET['q']);
}
?>Now change your body tag:
From: <body>
To: <body id="<?php print $body_id; ?>">
If you know of other uses for this snippet OR want to improve on it, feel free to do it in the comment form below.
Happy Styling!
Delicious
StumbleUpon
Propeller
Reddit
Magnoliacom
Newsvine
Furl
Facebook
Google
Yahoo
Technorati
Icerocket
