我的页面顶部有图像问题。
当url
是网站名称/菜单时,会显示image
。
当url
为websitename / node / 164时,image
消失。
因此,当级别为1时会显示image
,但当url-level
高于1时,image
会消失。
我在ZURB-Foundation
使用Drupal-7
主题。
这是我在page.tpl.php
<!--.page -->
<div role="document" class="page">
<?php
// Create a variable to hold the full path, in our theme, to the image.
// path_to_theme() takes care of creating the correct path for the active theme (which is likely your own custom one)
$my_static_banners = path_to_theme() . '/images/header/';
?>
<?php
if ($handle = opendir(path_to_theme() . '/images/header')) {
/* This is the correct way to loop over the directory. */
while (false !== ($picture = readdir($handle))) {
if($picture != "." && $picture != ".."){
$pictures[] = $picture;
}
}
$random = array_rand($pictures,1);
$header_picture = $pictures[$random];
closedir($handle);
}
?>
<!-- MENU-->
<!--.l-header region -->
<header role="banner" class="l-header" >
<div class="header-image" style="background-image:url(<?php print $my_static_banners.$header_picture ?>)">
</div>
</div>
...
答案 0 :(得分:0)
请尝试减少主题图层中的PHP代码量。
在您的页面模板中:
<div role="document" class="page">
<!-- MENU-->
<!--.l-header region -->
<header role="banner" class="l-header" >
<div class="header-image" style="background-image:url(<?php print $header_image; ?>);">
</div>
</div>
在主题中的template.php内或自定义模块中:
/**
* Implements hook_preprocess_page().
*/
function THEME_NAME_preprocess_page(&$variables) {
$variables['header_image'] = FALSE;
$images = _THEME_NAME_get_images();
if ($images) {
$random = array_rand($images, 1);
$variables['header_image'] = $images[$random];
}
}
/**
* Get images within a particular director.
*
* @return array
* An array of images for the header.
*/
function _THEME_NAME_get_images() {
$dir = drupal_get_path('theme', 'THEME_NAME') . '/images/header';
$images = array();
if (is_dir($dir) && $handle = opendir($dir)) {
while (FALSE !== ($filename = readdir($handle))) {
if ($filename[0] != '.') {
$images[] = $dir . $filename;
}
}
closedir($handle);
}
return $images;
}