Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Banner rotator

Featured Replies

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

  • 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

  • 2 weeks later...
  • Author

Hi right

 

been working on this and its doing my head in got the rotator working :D

 

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.