By donald7777 on
Hello here is the code i am using and no matter what i have tried different codes my header just will not change.
a better way to do this would be...
dharmanerd - February 18, 2008 - 22:05
this approach assumes you name your header images as such...
header-NODE_ID.jpg
example...
header-4.jpg
header-6.jpg
The benefit to using this approach is you simply need to add images to the directory using the naming convention above and the code will display them without further effort. You don't need to modify the php code every time you add a new header image.
<?php
$image_dir = '/path/to/images/';
$filename = $image_dir.'header-'.$node->nid.'.jpg';
if (file_exists($filename)) {
echo '<img src="$filename" alt="" />';
} else {
echo '<img src="'.$image_dir.'default.jpg" alt="" />';
}
?>
here is my page.tpl.php
<!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" lang="<?php echo get_page_language($language); ?>" xml:lang="<?php echo get_page_language($language); ?>">
<head>
<title><?php if (isset($head_title )) { echo $head_title; } ?></title>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<?php echo $head; ?>
<?php echo $styles ?>
<?php echo $scripts ?>
<!--[if IE 6]><link rel="stylesheet" href="<?php echo $base_path . $directory; ?>/style.ie6.css" type="text/css" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" href="<?php echo $base_path . $directory; ?>/style.ie7.css" type="text/css" media="screen" /><![endif]-->
<script type="text/javascript"><?php /* Needed to avoid Flash of Unstyle Content in IE */ ?> </script>
</head>
<body>
<div id="art-main">
<div class="art-Sheet">
<div class="art-Sheet-tl"></div>
<div class="art-Sheet-tr"></div>
<div class="art-Sheet-bl"></div>
<div class="art-Sheet-br"></div>
<div class="art-Sheet-tc"></div>
<div class="art-Sheet-bc"></div>
<div class="art-Sheet-cl"></div>
<div class="art-Sheet-cr"></div>
<div class="art-Sheet-cc"></div>
<div class="art-Sheet-body">
<div class="art-nav">
<div class="l"></div>
<div class="r"></div>
<?php if (!empty($navigation)) { echo $navigation; }?>
</div>
<div class="art-Header">
<div class="art-Header-jpeg"></div>
<div class="art-Logo">
<?php
if (!empty($site_name)) { echo '<h1 class="art-Logo-name"><a href="'.check_url($base_path).'" title = "'.$site_name.'">'.$site_name.'</a></h1>'; }
if (!empty($logo)) { echo '<div class="art-Logo-image"><img src="'. check_url($logo) .'" alt="'. $site_title .'" id="logo" /></div>'; }
?>
</div>
</div>
<?php if (!empty($banner1)) { echo $banner1; } ?>
<?php echo art_placeholders_output($top1, $top2, $top3); ?>
<div class="art-contentLayout">
<?php if (!empty($left)) echo '<div class="art-sidebar1">' . $left . "</div>";
else if (!empty($sidebar_left)) echo '<div class="art-sidebar1">' . $sidebar_left. "</div>";?>
<div class="<?php $l = null;
if (!empty($left)) $l = left;
else if (!empty($sidebar_left)) $l=sidebar_left;
$r = null;
if (!empty($right)) $r = right;
else if (!empty($sidebar_right)) $r=sidebar_right;
echo artxGetContentCellStyle($l, $r, $content); ?>">
<?php if (!empty($banner2)) { echo $banner2; } ?>
<?php if ((!empty($user1)) && (!empty($user2))) : ?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td width="50%"><?php echo $user1; ?></td>
<td><?php echo $user2; ?></td></tr>
</table>
<?php else: ?>
<?php if (!empty($user1)) { echo '<div id="user1">'.$user1.'</div>'; }?>
<?php if (!empty($user2)) { echo '<div id="user2">'.$user2.'</div>'; }?>
<?php endif; ?>
<?php if (!empty($banner3)) { echo $banner3; } ?>
<div class="art-Post">
<div class="art-Post-body">
<div class="art-Post-inner">
<div class="art-PostContent">
<?php if (!empty($breadcrumb)) { echo $breadcrumb; } ?>
<?php if (!empty($tabs)) { echo $tabs.'<div class="cleared"></div>'; }; ?>
<?php if (!empty($tabs2)) { echo $tabs2.'<div class="cleared"></div>'; } ?>
<?php if (!empty($mission)) { echo '<div id="mission">'.$mission.'</div>'; }; ?>
<?php if (!empty($help)) { echo $help; } ?>
<?php if (!empty($messages)) { echo $messages; } ?>
<?php echo art_content_replace($content); ?>
</div>
<div class="cleared"></div>
</div>
</div>
</div>
<?php if (!empty($banner4)) { echo $banner4; } ?>
<?php if (!empty($user3) && !empty($user4)) : ?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr valign="top"><td width="50%"><?php echo $user3; ?></td>
<td><?php echo $user4; ?></td></tr>
</table>
<?php else: ?>
<?php if (!empty($user3)) { echo '<div id="user1">'.$user3.'</div>'; }?>
<?php if (!empty($user4)) { echo '<div id="user2">'.$user4.'</div>'; }?>
<?php endif; ?>
<?php if (!empty($banner5)) { echo $banner5; } ?>
</div>
<?php if (!empty($right)) echo '<div class="art-sidebar2">' . $right . "</div>";
else if (!empty($sidebar_right)) echo '<div class="art-sidebar2">' . $sidebar_right . "</div>";?>
</div>
<div class="cleared"></div>
<?php echo art_placeholders_output($bottom1, $bottom2, $bottom3); ?>
<?php if (!empty($banner6)) { echo $banner6; } ?>
<div class="art-Footer">
<div class="art-Footer-inner">
<?php echo theme('feed_icon', url('rss.xml'), ''); ?>
<div class="art-Footer-text">
<?php
if (!empty($footer_message) && (trim($footer_message) != '')) {
echo $footer_message;
}
else {
echo '<p><a href="#">Contact Us</a> | <a href="#">Terms of Use</a> | <a href="#">Trademarks</a> | <a href="#">Privacy Statement</a><br />'.
'Copyright © 2010 '.$site_name.'. All Rights Reserved.</p>';
}
?>
<?php if (!empty($copyright)) { echo $copyright; } ?>
</div>
</div>
<div class="art-Footer-background"></div>
</div>
</div>
</div>
<div class="cleared"></div>
<p class="art-page-footer">Designed by <a href="">Donald MacKenzie</a>.</p>
</div>
<?php print $closure; ?>
</body>
</html>
and here is my template.php
<?php
// $Id
require_once("common_methods.php");
if (get_drupal_version() == 5) {
require_once("drupal5_methods.php");
}
else {
require_once("drupal6_methods.php");
}
/* Common methods */
function get_drupal_version() {
$tok = strtok(VERSION, '.');
//return first part of version number
return (int)$tok[0];
}
function get_page_language($language) {
if (get_drupal_version() >= 6) return $language->language;
return $language;
}
function get_full_path_to_theme() {
return base_path().path_to_theme();
}
/**
* Allow themable wrapping of all breadcrumbs.
*/
function nipca_theme_breadcrumb($breadcrumb) {
if (!empty($breadcrumb)) {
return '<div class="breadcrumb">'. implode(' | ', $breadcrumb) .'</div>';
}
}
function nipca_theme_service_links_node_format($links) {
return '<div class="service-links"><div class="service-label">'. t('Bookmark/Search this post with: ') .'</div>'. art_links_woker($links) .'</div>';
}
/**
* Theme a form button.
*
* @ingroup themeable
*/
function nipca_theme_button($element) {
// Make sure not to overwrite classes.
if (isset($element['#attributes']['class'])) {
$element['#attributes']['class'] = 'form-'.$element['#button_type'].' '.$element['#attributes']['class'].' art-button';
}
else {
$element['#attributes']['class'] = 'form-'.$element['#button_type'].' art-button';
}
return '<span class="art-button-wrapper">'.
'<span class="l"></span>'.
'<span class="r"></span>'.
'<input type="submit" '. (empty($element['#name']) ? '' : 'name="'. $element['#name']
.'" ') .'id="'. $element['#id'].'" value="'. check_plain($element['#value']) .'" '. drupal_attributes($element['#attributes']).'/>'.
'</span>';
}
/**
* Image assist module support.
* Using styles in IE
*/
function nipca_theme_img_assist_page($content, $attributes = NULL) {
$title = drupal_get_title();
$output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
$output .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">'."\n";
$output .= "<head>\n";
$output .= '<title>'. $title ."</title>\n";
// Note on CSS files from Benjamin Shell:
// Stylesheets are a problem with image assist. Image assist works great as a
// TinyMCE plugin, so I want it to LOOK like a TinyMCE plugin. However, it's
// not always a TinyMCE plugin, so then it should like a themed Drupal page.
// Advanced users will be able to customize everything, even TinyMCE, so I'm
// more concerned about everyone else. TinyMCE looks great out-of-the-box so I
// want image assist to look great as well. My solution to this problem is as
// follows:
// If this image assist window was loaded from TinyMCE, then include the
// TinyMCE popups_css file (configurable with the initialization string on the
// page that loaded TinyMCE). Otherwise, load drupal.css and the theme's
// styles. This still leaves out sites that allow users to use the TinyMCE
// plugin AND the Add Image link (visibility of this link is now a setting).
// However, on my site I turned off the text link since I use TinyMCE. I think
// it would confuse users to have an Add Images link AND a button on the
// TinyMCE toolbar.
//
// Note that in both cases the img_assist.css file is loaded last. This
// provides a way to make style changes to img_assist independently of how it
// was loaded.
$output .= drupal_get_html_head();
$output .= drupal_get_js();
$output .= "\n<script type=\"text/javascript\"><!-- \n";
$output .= " if (parent.tinyMCE && parent.tinyMCEPopup && parent.tinyMCEPopup.getParam('popups_css')) {\n";
$output .= " document.write('<link href=\"' + parent.tinyMCEPopup.getParam('popups_css') + '\" rel=\"stylesheet\" type=\"text/css\">');\n";
$output .= " } else {\n";
foreach (drupal_add_css() as $media => $type) {
$paths = array_merge($type['module'], $type['theme']);
foreach (array_keys($paths) as $path) {
// Don't import img_assist.css twice.
if (!strstr($path, 'img_assist.css')) {
$output .= " document.write('<style type=\"text/css\" media=\"{$media}\">@import \"". base_path() . $path ."\";<\/style>');\n";
}
}
}
$output .= " }\n";
$output .= "--></script>\n";
// Ensure that img_assist.js is imported last.
$path = drupal_get_path('module', 'img_assist') .'/img_assist_popup.css';
$output .= "<style type=\"text/css\" media=\"all\">@import \"". base_path() . $path ."\";</style>\n";
$output .= '<!--[if IE 6]><link rel="stylesheet" href="'.get_full_path_to_theme().'/style.ie6.css" type="text/css" /><![endif]-->'."\n";
$output .= '<!--[if IE 7]><link rel="stylesheet" href="'.get_full_path_to_theme().'/style.ie7.css" type="text/css" /><![endif]-->'."\n";
$output .= "</head>\n";
$output .= '<body'. drupal_attributes($attributes) .">\n";
$output .= theme_status_messages();
$output .= "\n";
$output .= $content;
$output .= "\n";
$output .= '</body>';
$output .= '</html>';
return $output;
}
Comments
You do not provide any
You do not provide any context for the first chunk of code and it has not obvious relation to page.tpl.php (there needs to be one).
Just Worked That Out Myself
Here's how it worked for me:
(1) I'm using the images as backgrounds, and the code below works accordingly;
(2) am storing the images in /images folder inside my theme folder - the
. base_path() .$directory .navigates to your theme directory.Note that the first condition checks for your Homepage, and displays a predetermined header file name since your Homepage may not have a node-id.
The easiest way to implement this, is to create a block with this code inside it, and drop it into your header region.
Works Perfect
This is what I have been looking for for a few days. Thanks!
the first chunk of code gets
the first chunk of code gets pasted in your page.tpl.php file under the header. That should allow it to change your header.