Last updated August 26, 2009. Created by Dublin Drupaller on June 23, 2007.
Edited by bekasu, bryan kennedy. Log in to edit this page.
description
This snippet allows you to load a custom layout file and override the site logo and site name based on path.
Thanks to thomasmurphy for contributing the original snippet.
usage
As an illustrative example, the following step-by-step approach shows you how load a custom blog page layout file and switch the site logo and site name for when users are viewing blogs.
Step 1 of 2
- make a copy of your page.tpl.php file and rename it to be page-blog.tpl.php.
- Using a text editor like notepad.exe or equivalent, modify the layout of page-blog.tpl.php file to suit your desires
- Upload your new page-blog.tpl.php layout file to your active theme folder
Step 2 of 2
- Using a text editor like notepad.exe or equivalent, paste the snippet below into your template.php file.
- Upload your edited template.php file to your active theme folder and your new layouts will take effect automatically
<?php
/**
* This snippet loads a custom page-blog.tpl.php layout file and
* overrides the logo and site name when users
* are viewing blogs.
*/
function _phptemplate_variables($hook, $variables = array()) {
switch ($hook) {
case 'page':
if ((arg(0) == 'blog')) {
$variables['template_file'] = 'page-blog'; // loads the custom page-blog.tpl.php file
$variables['site_name'] = 'blog section name'; // change the site name
$variables['logo'] = '/path/to/newlogo/logo.png'; // change the site logo
}
break;
}
return $variables;
}
?>notes
- See also this handbook page: Changing the site logo, name and layout for multiple paths and sections
- More snippets to follow, including changing the site name and logo based on node type, taxonomy etc.