Share

From this page you can share Drupal Themes: Different body tags based off the URL to a social bookmarking site or email a link to the page.
Social WebE-mail

Thank you for your interest in spreading the word on Elvis Blogs.

NOTE: We only request your email address so that the person you are recommending the page to knows that you wanted them to see it, and that it is not junk mail. We do not capture any email address.

Enter multiple addresses on separate lines or separate them with commas. You can only email up to 5 recipients
(Your Name) has forwarded a page to you from Elvis Blogs
(Your Name) thought you would like to see this page from the Elvis Blogs web site.

Drupal Themes: Different body tags based off the URL

Drupal Themes: Different body tags based off the URL

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! (read more)