December 17, 201015 yr Hi folks I have created an <ul> out of a foreach loop and its displaying image urls from a database. I want to know how i could have one img displayed and automatically change like every 30 secs. Looked at some free scripts but cant get them working lol. Also im using cakephp. Thanks in advance Joe
December 17, 201015 yr the jQuery cycle plugin is usually a good option Edited December 17, 201015 yr by mrchristoph
December 17, 201015 yr Author put all the code for the cycle plugin in the head of my page like below doesnt seem to work though. have i done it wrong <!-- include jQuery library --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script> <!-- include Cycle plugin --> <script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.2.74.js"></script> <!-- initialize the slideshow when the DOM is ready --> <script type="text/javascript"> $(document).ready(function() { $('.banner').cycle({ fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc... }); }); </script> </head> Code where i want the rotator: <?php // Looping through the first group: foreach($banners as $banner){ ?> <div class="banner"> <ul class="banner"> <li><?php echo $html->link( $html->image($banner['Banner']['path'], array('width'=>'474', 'height'=>'68', 'border'=>0)) , "{$banner['Banner']['url']}" ,array('target'=>'_blank', 'alt'=>$banner['Banner']['description']), null, false ); ?> </li> </ul> </div> <?php } ?> Thanks guys Joe
January 1, 201115 yr Author Hi right been working on this and its doing my head in got the rotator working but added two fields to the db - company and position I then removed the description field. Now it has broke its displaying nothing here's my code index_viex <div id="banner"> <?php if(!empty($banners) && ($banners['Banner']['position']=='Top')){ foreach($banners as $banner){ ?> <a href="<?php echo $banner['Banner']['url']; ?>"><img src="<?php echo $banner['Banner']['path']; ?>" alt="<?php echo $banner['Banner']['company']; ?>" /></a> <?php } } ?> </div> banner_controller <?php class BannersController extends AppController { var $name = 'Banners'; var $helpers = array('Html', 'Form', 'Ajax','Javascript'); var $layout = 'ajax'; var $components = array('Session', 'Cookie'); function beforeFilter() { parent::beforeFilter(); $this->Auth->allow('index','featrot'); if(strpos($this->here, 'admin')) { $this->layout = 'admin'; } } function index() { Configure::write('debug',0); $this->Banner->recursive = 0; $this->paginate['Banner']; $banners = $this->paginate(); if($banners) { $this->set('banners', $banners); } } function featrot() { Configure::write('debug',0); $this->Banner->recursive = 0; $this->paginate['Banner']; $banners = $this->paginate(); if($banners) { $this->set('banners', $banners); } } function admin_edit(){ $this->pageTitle='Admin section - .: Banners Edit:.'; $banners = $this->Banner->find('first'); $id = $banners['Banner']['id']; if (!empty($this->data)) { $this->Banner->id = $id; if ($this->Banner->save($this->data)) { $this->Session->setFlash(__('The Banner has been updated', true)); } else { $this->Session->setFlash(__('The Banner could not update. Please, try again.', true)); } } if (empty($this->data)) { $this->data = $this->Banner->read(null, $id); } } function admin_display_banners($id=null){ $this->pageTitle='Admin section - .: Banners Setting :.'; if (!empty($this->data)) { $this->Banner->id = $id; if ($this->Banner->save($this->data)) { $this->Session->setFlash(__("Banner#$id has been updated", true)); $this->Banner->id = null; } else { $this->Session->setFlash(__("Banner#$id could not update. Please, try again.", true)); } } $this->data = null; $this->Banner->recursive = -1; $this->paginate['Banner']; $banners = $this->paginate('Banner'); $this->set('banners', $banners); } } ?> banner model: <?php class Banner extends AppModel { var $name = 'Banner'; } ?> btw it was a friend of a friend who added this in for me so i dont know if there is any other files I should be showing you. It was working until I done that. Thanks guys Joe
Create an account or sign in to comment