Would it be possible to add this into the template so we could have rotating images in the header:

http://slayeroffice.com/code/imageCrossFade/index.html

I got the idea from a joomla template called ja_antares which also switches text and font colours but changes the stylesheet being used to ensure persistent styles are kept when new links are ticked.

Comments

derjochenmeyer’s picture

Hi drupalfool,

it should be easy to implement. But the problem i see is that many people will not need or want this feature...

i am still thinking about the right implementation for the coor switcher... ;-)

drupalferret’s picture

Can you tell me how to implement the image switcher code and I will customise the template then write a tutorial for others to follow so if they want it they can implement it.

Secondly, if it will help I can supply a copy of our Joomla template which uses different css stylesheets and javascript to keep the new styles set once chosen. This should give you an idea how others have approached and resolved this albeit on a different cms platform

derjochenmeyer’s picture

i would recommend this script here... it uses jquery...

http://medienfreunde.com/lab/innerfade/

im sorry, i dont have much time these days... otherwise i would try to explain how you can implement it ... but if you look at the source code it should explain itself.. you need a div container that has a certain name (id)... then just include the javascript at the head of the page.tpl.php and it will do its magic ;-)

drupalferret’s picture

I have downloaded the image rotator script as you suggested and uploaded jsquery.innerfade.js to the misc folder of the drupal installation.

have placed the following call to the script in template.php within the fourseasons adminwidget function call:

I am not sure which part of the template holds the header images so I do not know where to place the following code:

<script type="text/javascript">
	   $(document).ready(
				function(){
								
					$('.headerimg').innerfade({
						speed: 1000,
						timeout: 5000,
						type: 'sequence',
						containerheight: '220px'
					});
				});
  	</script>
<div class=".headerimg">
<img src="images/header0.jpg" alt="header image 0" />
<img src="images/header1.jpg" alt="header image 1" />
<img src="images/header2.jpg" alt="header image 2" />
<img src="images/header3.jpg" alt="header image 3" />
</div>
derjochenmeyer’s picture

as a general tip. Downlaod Firefox. Then download the Firebug Plugin.

It will help you a lot in figuring out what is going on in your template and where. Rcightclick on any element on a website and select "Inspect Element" from the firebug menu. It will show you the html source for any given element and it will show you which css information exists in all the different css files (and which is used).

The code of the innerfade script should all be put into the page.tpl.php ... but i didnt have the time to try it myself... Use Firebug, it will help you...

drupalferret’s picture

Hi - I am already using the firefox web developer plugin and I have located the various div elements for the containers. But the part I cannot get to work is adding the javascript to the head section of the page. I tried various methods, including placing the following code into template.php to import the javascript at page-load time:

This loaded the javascript into the body of the page not the header. I then tried to add the javascript into the head section of page.tpl.php but this threw errors and broke the template. For info jquery.header-img.js looks like this: $(document).ready( function(){ $('#header-img').innerfade({ speed: 1000, timeout: 3000, type: 'sequence', containerheight: '200px' }); });

the div tag for #header-img inside page.tpl.php looks like this:

Only local images are allowed.
Only local images are allowed.
Only local images are allowed.
Only local images are allowed.
      if (!empty($mission)) {
        print '<div id="site-mission">'.$mission.'</div>';
      }
    

Unfortunatly this script needs to be loaded directly into the head section and so far I have only managed to get it into the body section. Can you suggest anything?

derjochenmeyer’s picture

First: dont place the js code in the drupal/misc folder ;-) put all the custom template stuff in the theme folder

it should be something like sites/all/themes/fourseasons/innerfade/jquery.innerfade.js

then add somehting like this to your template.php

<?php
drupal_add_js(base_path() . 'sites/all/themes/fourseasons/innerfade/jquery.innerfade.js');
drupal_add_js('
  $(document).ready(function(){
    $('#header-img').innerfade({
      speed: 1000,
      timeout: 3000,
      type: 'sequence',
      containerheight: '200px'
    });
  });
', inline);

?>
drupalferret’s picture

I tried pasting your code above directly into template.php at the end of all the existing functions and I got an error message: Parse error: syntax error, unexpected '<' in .....

In other words it is stopping at the opening <php tag.

Am I supposed to put this into template.php inside an existing function or do I create a new function?

Sorry - I am not a programmer. Thanks for your help so far :)

derjochenmeyer’s picture

i was a bit fast, try this without the php delimiters:

<?php
drupal_add_js(base_path() . 'sites/all/themes/fourseasons/innerfade/jquery.innerfade.js');
drupal_add_js('
  $(document).ready(function(){
    $("#header-img").innerfade({
      speed: 1000,
      timeout: 3000,
      type: "sequence",
      containerheight: "200px"
    });
  });
', inline);

?>

if i had more time i would really try to help you out, but im doing this while my customers are writing angry mails ;-)

zilla’s picture

if it helps, the marinelli theme for d6 has rotating banners - perhaps you could look over his code?
http://drupal.org/project/marinelli

drupalferret’s picture

Status: Closed (fixed) » Active

Thanks for all the help on this - I finally managed to get it to work. For anyone else who wants to get a rotating header image here is what to do:

1) Download this script which works nicely with jquery http://medienfreunde.com/lab/innerfade/
2) Create a folder called innerfade in your fourseasons theme directory.
3) Upload the file jquery.innerfade.js to your innerfade folder
4) Open template.php and paste this code at the bottom

drupal_add_js(path_to_theme('fourseasons') . '/innerfade/jquery.innerfade.js');
drupal_add_js('
 $(document).ready(function(){
  $("#header-image img").show();
  $("#header-image").innerfade({
    speed: 1000,
    timeout: 6000,
    type: "sequence",
    containerheight: "200px"
  });
 });
', inline);

Please note: the above code must be before the ?> at the end.

5) Open page.tpl.php and find the header-image div tag then place your image references inside it like this: (note I have put in two variables which tells drupal to put the full path to the template folder)

<div id="header-image">
<img src="<?php print base_path() ?>/<?php print path_to_theme() ?>/img/header/header_image0.jpg" alt="header image 0" />
<img style="display:none;" src="<?php print base_path() ?>/<?php print path_to_theme() ?>/img/header/header_image1.jpg" alt="header image 1" />
</div>

Remember to put in the rest of your images - as many as you need. You can also have them linking to somewhere else if required and can play with the timers within the template.php code.

Note: The tag for header image 1 id different from the first one. Image 1 has a style next to the img tag to hide the image. Image0 does not have this inline style because we want it to display first. This is important to stop all images being loaded at once to the screen. So for each extra image you add after image0 needs to use the second tag. e.g.:

<img style="display:none;" src="<?php print base_path() ?>/<?php print path_to_theme() ?>/img/header/header_image1.jpg" alt="header image 1" />
<img style="display:none;" src="<?php print base_path() ?>/<?php print path_to_theme() ?>/img/header/header_image2.jpg" alt="header image 2" />
<img style="display:none;" src="<?php print base_path() ?>/<?php print path_to_theme() ?>/img/header/header_image3.jpg" alt="header image 3" />

6) Upload template.php and page.tpl.php and make sure the images are in the correct folder when you upload them. (in this case img/header)

Refresh your website and the header should start displaying a rotating banner.

Note: By changing the code in template.php you can have the images in sequence or random order.

Hope this helps someone to make this superb template a little more personal for their site.

Drupafool (Jim)

tdh’s picture

Is this on a live site? I would like to see it in action with the four seasons theme. Thanks.

derjochenmeyer’s picture

hey drupalfool, thanks for the great step by step tutorial. Happy you managed to get it working...

drupalferret’s picture

** Bugfix to Image Rotator **
There was a problem with the images flashing before the page loaded the javascript. The following fixes this problem: (Thanks derjochenmeyer)

1) Open page.tpl.php and add the following code next to the img tag for each image except the first one:

style="display:none;"

so the image tag should now look like this:

<img src="<?php print base_path() ?>/<?php print path_to_theme() ?>/img/header/header_image0.jpg" alt="header image 0" />
<img style="display:none;" src="<?php print base_path() ?>/<?php print path_to_theme() ?>/img/header/header_image1.jpg" alt="header image 1" />
<img style="display:none;" src="<?php print base_path() ?>/<?php print path_to_theme() ?>/img/header/header_image2.jpg" alt="header image 2" />

Next open template.php and change add this to the code:

$("#header-image img").show();

so the template.php code for our image rotator should now look like this:

drupal_add_js(path_to_theme('fourseasons') . '/innerfade/jquery.innerfade.js');
drupal_add_js('
 $(document).ready(function(){
  $("#header-image img").show();
  $("#header-image").innerfade({
    speed: 1000,
    timeout: 6000,
    type: "sequence",
    containerheight: "200px"
  });
 });
', inline);

For the sake of completeness I have edited the tutorial above with the new code

derjochenmeyer’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

Vially’s picture

Hi drupalfool, and thanks for sharing your work with us first of all. I have followed your step by step tutorial and it works beautifully.

However, there is something weird going on with this js. Yesterday someone said that the images were switching too fast and indeed, it seemed right to me. I opened the small javascript file and modified the time between slides from 2000 to 10000, but to my surprise, nothing changed, or at least the duration between the slides is not 10 secs but more close to 4 secs. Could you please check your implementation and see if you can change the slide duration ?

Thanks a lot.

Later edit: Yes, I have cleared the cache :)

drupalferret’s picture

Hi Vially
Have you got a url where I can see the problem in action?
Thanks

drupalferret’s picture

Try first changing the time in template.php. Look for this code and change the speed to 3000 and the timeout to 20000 then see what happens:

drupal_add_js(path_to_theme('fourseasons') . '/innerfade/jquery.innerfade.js');

drupal_add_js('
$(document).ready(function(){
$("#header-image img").show();
$("#header-image").innerfade({
speed: 3000,
timeout: 20000,
type: "sequence",
containerheight: "200px"
});
});
', inline);

==========
NOTES:
==========

Transition Time
The setting: speed: 3000 sets the transition speed between the pictures. In this case the transition time is 3 seconds between pictures. Increasing this to 5000 will make the transition time 5 seconds between pictures.

Display Time
The setting: timeout: 20000 sets the picture display time. In this case the picture is displayed for 20 seconds then the next one for 20 seconds. Increasing this value will increase the time for which the picture is displayed.

drupalferret’s picture

I received a really nice email from Todd Hoegner (drupal username tdh) who told me how pleased he was with the Image Rotator tutorial. He had been playing around with it and managed to get it working by placing the images inside a block. Naturally this gives you a lot of control over where it can be placed and brings up a whole host of potential uses. Todd kindly documented how he did it and his tutorial is below:

====================================================

How to get the image rotator working using blocks

====================================================
Tutorial originally created for header images by drupalfool and adapted by tdh to work inside blocks.

1) Download this script which works nicely with jquery http://medienfreunde.com/lab/innerfade/

2) Create a folder off of your main drupal installation for /images/rotate

3) Upload the file jquery.innerfade.js to this folder

4) Open template.php and paste this code at the bottom:

drupal_add_js('/images/rotate/jquery.innerfade.js');
drupal_add_js('
$(document).ready(function(){
$("#rotate-image img").show();
$("#rotate-image").innerfade({
speed: 1000,
timeout: 8000,
type: "sequence",
containerheight: "132px"
});
});
', inline);

Please note: the above code must be before the ?> at the end.

5) Create a new block and paste the following code in the block (be sure to use full html for the block):

<div id="rotate-image">
<img src="/images/rotate/picture1.gif" alt="header image 0" /><img style="display:none;"src="/images/rotate/picture2.gif" alt="header image 2" /><img style="display:none;" src="/images/rotate/picture3.gif" alt="header image 3" />
</div>

You can add as many images as you like, the first image must use the code like:

<img src="/images/rotate/picture1.gif" alt="header image 0" />

The remaining images must use the code like:

<img style="display:none;" src="/images/rotate/picture2.gif" alt="header image 2" />

Also, with the block, the images must not have any character returns between them, they must
all be on the same line (text wrapping within the block is ok, just not a new line). If the images are not all on the same line, blank spots will be added in between the images and the following images after the first one will "jump" up a bit.

6) Upload template.php and make sure the images are in the correct folder when you upload them (in
this case images/rotate)

7) Visit the blocks administration and activate the newly created block to where you would like it to display.

Refresh your website and the header should start displaying a rotating banner.

Note: By changing the code in template.php you can have the images in sequence or random order.

Transition Time
The setting: speed: 1000 sets the transition speed between the pictures. In this case the transition
time is 1 seconds between pictures. Increasing this to 5000 will make the transition time 5 seconds
between pictures.

Display Time
The setting: timeout: 8000 sets the picture display time. In this case the picture is displayed for
8 seconds then the next one for 8 seconds. Increasing this value will increase the time for which the
picture is displayed.

frednwright’s picture

Status: Active » Closed (fixed)
StatusFileSize
new4.69 KB
new3.16 KB

Drupalfool,

First of all - thanks so much for taking the time to make this tutorial! If we all do what you have done for the various problems that we solve, this site will become an even more effective resource and more attractive to newcomers.

I am trying to implement Innerfade on a theme called Ad Agency. I can't get it to work! I am attaching the page.tpl.php file and template.php. The pertinent div ID is "homepic". I am trying to get the big central banner to rotate. I realize you don't have time to do this for every single theme, but any ideas or help you can give me would be GREATLY appreciated!

Fred

drupalferret’s picture

Hi frednwright

The following code seems to be missing from your template.php:

drupal_add_js(path_to_theme('ad_agency') . '/innerfade/jquery.innerfade.js');
drupal_add_js('
$(document).ready(function(){
  $("#header-image img").show();
  $("#header-image").innerfade({
    speed: 1000,
    timeout: 6000,
    type: "sequence",
    containerheight: "200px"
  });
});
', inline);
Etje’s picture

Thanks for the really nice work guys. I am trying to have this working on my own site. The given code implements a fixed list of images. I would like to let my users upload photo's to a certain folder (eg files\images\header) through a header-node with a cck image-field. Does anyone know a solution to have innerfade collect the images from this folder automatically (as in: without me adding img-statements manually)?

Etje

jlatham06’s picture

I am having a small issue with the image rotator. The rotator works fine, but I cannot seem to center it on the block without it messing up. It will center, but then displays all of the images it is supposed to rotate, instead of just rotating in new images in the same spot. Please help.

shittii’s picture

StatusFileSize
new5.54 KB

I'm trying to get Image Rotator working inside a block. I'm loosing my mind here! I'm using the Ubiquity theme and just like in Four Season theme, I cannot find the ?> at the end of theme's template.php! So I'm truly clueless where to paste this snippet:

drupal_add_js('/images/rotate/jquery.innerfade.js');
drupal_add_js('
$(document).ready(function(){
$("#rotate-image img").show();
$("#rotate-image").innerfade({
speed: 1000,
timeout: 8000,
type: "sequence",
containerheight: "132px"
});
});
', inline);

Here's the template.php attached. I have followed drupalfool's (and tdh's) guides carefully. I assume I don't need to modify my page.tlp.php?

derjochenmeyer’s picture

Hi shittii, just put it at the end... there is not always a ?> at the end of the template file...

then you need to modify your tpl.php file!

this jquery looks for a div with an id called "rotate-image"

so in your tpl.php file there should be something like:

<div id="rotate-image">
  <img src="<?php print base_path() ?>/<?php print path_to_theme() ?>/img/header/header_image0.jpg" alt="header image 0" />
  <img style="display:none;" src="<?php print base_path() ?>/<?php print path_to_theme() ?>/img/header/header_image1.jpg" alt="header image 1" />
  <img style="display:none;" src="<?php print base_path() ?>/<?php print path_to_theme() ?>/img/header/header_image2.jpg" alt="header image 2" />
  <img style="display:none;" src="<?php print base_path() ?>/<?php print path_to_theme() ?>/img/header/header_image3.jpg" alt="header image 3" />
</div>

make sure the images are in your themes folder under /img/header/

EDIT: sorry forgot you wanted to use that in a block... you have to create a block template file for this block and put the code above ... or the easier way is: create a block on the blocks administration screen... set the input filter to PHP and then paste the code above ...

workbench’s picture

I've tried to make this work in drupal 6.2 but with no luck...

It only slides the alt text "header image 0" etc...

This is how the page.tpl.php looks like;

<div id="header-image">
<img src="<?php print base_path() ?>/<?php print path_to_theme() ?>/img/header/0.jpg" alt="header image 0" />
<img style="display:none;" src="<?php print base_path() ?>/<?php print path_to_theme() ?>/img/header/1.jpg" alt="header image 1" />
<img style="display:none;" src="<?php print base_path() ?>/<?php print path_to_theme() ?>/img/header/2.jpg" alt="header image 2" />

And template.php;

drupal_add_js(path_to_theme('fourseasons') . '/innerfade/jquery.innerfade.js');
drupal_add_js('
$(document).ready(function(){
  $("#header-image img").show();
  $("#header-image").innerfade({
    speed: 1000,
    timeout: 6000,
    type: "sequence",
    containerheight: "80px"
  });
});
', inline);
?>

Don't know if I have to edit style.css, but it look like this;

#header-image {
  height:80px;
  background-color:#FF9900;
  background-image:url(img/headerimg.jpg);
  background-repeat:no-repeat;

The script doesn't want to slide images - only the text.
It should look easy to fix, but I've tried everything.
Images are stored at themes/fourseasons/img/header/ and named as I've wrote page.tpl.php

Help please?

spcomputing’s picture

I'm having the exact same problem as workbench. Has anybody been able to get this to work on Drupal 6.2? Can we re-open this issue?

derjochenmeyer’s picture

For everybody, looking for an Image rotator, there is anohter solution that i used in a site that im working on right now for D6. Wait 6 seconds on the frontpage ;-)

DEMO: http://www.arco-mountainexperts.com/

I use the jquery cycle plug-in, which offers a lot of effects: http://malsup.com/jquery/cycle/

In my page.tpl.php i use the following code:

<div id="headerimages">
  <img src="/PathToImg/header.jpg" width="765" height="366" />
</div>

then (simplyfied for this example) i use the following code in the template.php (make sure you download and copy the plug-in from the project page http://malsup.com/jquery/cycle/):

  drupal_add_js('PathToPlugin/jquery.cycle.all.pack.js', 'module');
  drupal_add_js('
    $(document).ready( function () {  
      $("#headerimages").append("<img src=\"//PathToImg/header1.jpg\" style=\"display:none;\" width=765 height=366 />");
      $("#headerimages").append("<img src=\"//PathToImg/header2.jpg\" style=\"display:none;\" width=765 height=366 />");
      $("#headerimages").append("<img src=\"//PathToImg/header3.jpg\" style=\"display:none;\" width=765 height=366 />");
      $("#headerimages").append("<img src=\"//PathToImg/header4.jpg\" style=\"display:none;\" width=765 height=366 />");
      
      $("#headerimages").cycle({ 
        fx:     "fade", 
        speed:   1500, 
        timeout: 6000, 
        next:   "#headerimages", 
        pause:   1
      });
    });
  ', 'inline');

* this approach adds the additional images (hidden) after the page has loaded, using jquerys append().
* then initiallizes the cycle plugin
* check the plugin homepage for instructions, how to use all the cool effects: http://malsup.com/jquery/cycle/

spcomputing’s picture

derjochenmeyer,

Excellent post, thank you!

For some reason the path to the images that you specified in your template.php code didn't work for me. I had to change it to this:

$("#headerimages").append("<img src="PathToImg/header2.jpg\" style=\"display:none;\" width=765

Again, thank you for a very helpful post.

orange peel’s picture

**edit** nevermind on the JQuery Cycle Lite, got it to work, thanks for the code, I love it!! I just wish IE 7 faded/transistioned cleaner like Firefox does for png files. IE outlines the images in black when it fades, Firefox just fades away clean and clear.

-Scott

drupalferret’s picture

To make the original code work in Drupal 6.X you need to remove the extra / in the line of PHP then follow the original instructions. I have to admit - I never noticed the coding error myself until someone else pointed it out.

The error is as follows (notice the extra / between php statements)

  <img src="<?php print base_path() ?>/<?php print path_to_theme() ?>/img/header/header_image0.jpg" alt="header image 0" />
  

It should actually look like this:

<div id="rotate-image">
  <img src="<?php print base_path() ?><?php print path_to_theme() ?>/img/header/header_image0.jpg" alt="header image 0" />
  <img style="display:none;" src="<?php print base_path() ?><?php print path_to_theme() ?>/img/header/header_image1.jpg" alt="header image 1" />
  <img style="display:none;" src="<?php print base_path() ?><?php print path_to_theme() ?>/img/header/header_image2.jpg" alt="header image 2" />
  <img style="display:none;" src="<?php print base_path() ?><?php print path_to_theme() ?>/img/header/header_image3.jpg" alt="header image 3" />
</div>

Sorry - I have not had time to try the newer version and write a tutorial yet - been really busy since I got back and trying to catch up again.

scottrigby’s picture

Thanks drupalfool – #14 works for my 5.9 site. Cheers! Scott

sangu’s picture

Project: Four Seasons » Green-n-Black
Version: 5.x-1.8 » 5.x-1.2
Category: feature » support

Hi,
I tried image rotator using blocks as given by drupalfool - March 30, 2008 - 20:26 (#20), and it was a success until i checked it in Internet Explorer 6.0. It works all right in Firefox.
In I.E., i can see only the first image (no fading, nothing).
Here is how i used it:

.
.
.
<script type="text/javascript" src="/drupal5/images/rotate/jquery.innerfade.js"></script>
<script type="text/javascript" src="/drupal5/images/rotate/jquery.js"></script>
.
.
.
<script type="text/javascript">
$(document).ready(function(){
$("#rotate-image img").show();
$("#rotate-image").innerfade({
speed: 3000,
timeout: 6000,
type: "sequence",
containerheight: "320px"
});
});
</script>
<div class="content">
<div id="rotate-image">
<img src="/drupal5/images/rotate/pic1.png" alt="header image 0"  />
<img style="display:none;"src="/drupal5/images/rotate/pic2.png" alt="header image 1" />
<img style="display:none;" src="/drupal5/images/rotate/pic3.png" alt="header image 2" />
<img style="display:none;" src="/drupal5/images/rotate/pic4.png" alt="header image 3" />
<img style="display:none;" src="/drupal5/images/rotate/pic5.png" alt="header image 4" />
<img style="display:none;" src="/drupal5/images/rotate/pic6.png" alt="header image 5" />
</div>
</div>

Did anyone come across this problem in I.E.? Help would be appreciated.

Thanks.

khan2ims’s picture

Hi,

This is working like a charm on my site ..

I have a problem though .. Right now its left aligned .. I want to right align it and put content on the left, like we do for riight aligned images .. But when I am trying to right align by

it is not showing up as rotating images but right aligned images one below the other ... Same thing is happening, when using under . Also tried defining new class for images and then giving float: right; But without success.

i am using a custom theme

Anybody, plz guide me !!!

khan2ims’s picture

Hi,

I was also wondering if its possible to stop playing of image rotator after first play .. If we would give a kind of stop/ play button?

fletchgqc’s picture

There's a module called "slideshow_creator" that does a lot of this for you. But it's got a few wierd features like it crops pictures. Anyway the code in #29 is excellent - but it's better to install the jquery_plugins module and change one of the add_js lines to:

drupal_add_js(drupal_get_path('module', 'jquery_plugin') .'/jquery.cycle.min.js');
khan2ims’s picture

Earlier I was using script mentioned by derjochenmeyer. But today I saw that the rotating images are no more working. I tried making changes for Drupal 6 but without result. Then I went through these steps for block mentioned by drupalfool and successfully pulled it off for our home page @ http://www.newearthmarketing.com

Great!! Thanks.

Imran Khan
Project Manager
New Earth Marketing