Add Start and End Date limit Joomla 1.5 Banners
On my recent project which uses Joomla v1.5, my client asks for banner management with ability to manage banner based on number of impression or date (period of time). Quick search on Joomla extension repositories show that there are many banner management component and module for Joomla 1.0 but not Joomla 1.5. Most of them which run on 1.5 are module to add animation or customize the display of your banner. At the time I write this blog, I found one component which does this, but it’s fairly plain and does not allow me to limit the banner based on number of impression made, categorize my banners, and keep track of clients.
Fortunately, the default Joomla 1.5 comes with com_banners and mod_banners core component and it has everything I need except start and end date setting to publish banner/ads. So let’s modify this core component to add this feature.
There are two files that you need to edit. First, open up \administrator\components\com_banners\views\banner.php with your favourite editor. Then insert the following codes on line 347 (between </tr> and <tr>).
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | <?php // BEGIN EDIT - Enable Start and End Date of Banner function formatToShortDate($date) { $date = substr($date,0,10); if ($date == '0000-00-00') return ""; return $date; } ?> <tr> <td class="key"> <?php echo JText::_( 'Start Date' ); ?> </td> <td> <?php echo JHTML::_('calendar', formatToShortDate($row->publish_up) , 'publish_up', 'publish_up', '%Y-%m-%d', array('class'=>'inputbox', 'size'=>'25', 'maxlength'=>'19')); ?></td> </tr> <tr> <td class="key"> <?php echo JText::_( 'End Date' ); ?> </td> <td> <?php echo JHTML::_('calendar', formatToShortDate($row->publish_down) , 'publish_down', 'publish_down', '%Y-%m-%d', array('class'=>'inputbox', 'size'=>'25', 'maxlength'=>'19')); ?></td> </tr> <?php // END EDIT - Enable Start and End Date of Banner ?> |
Secondly, locate and edit \components\com_banners\models\banner.php.
Try to find this line $wheres[] = ‘(imptotal = 0 OR impmade < imptotal)’;. On my file it’s located on line number 41, and below that add the following code:
42 43 44 45 | // BEGIN EDIT - Enable Start and End Date of Banner $wheres[] = "(publish_up = '0000-00-00 00:00:00' OR publish_up <= CURDATE())"; $wheres[] = "(publish_down = '0000-00-00 00:00:00' OR publish_down >= CURDATE())"; // END EDIT - Enable Start and End Date of Banner |
It’s done. Now you will have start and end date field when you create new or edit your banners. The mod_banners will only display ads/banners which sit after the start date (if set) and before the end date (if set). You can leave start and end date field empty to ignore them. Please leave comments if you are satisfied or face any problem. Cheers.
Tags: banner, joomla, modification
















February 3rd, 2009 at 7:57 am
Great hack. Works perfectly.
February 11th, 2009 at 11:06 pm
I love the powerful simplicity!
February 24th, 2009 at 1:19 pm
Thanks, Thanks,,, and Thanks. Good job.
March 20th, 2009 at 7:31 pm
Great hack! so simple yet so handy and powerful!!
Should really be a feature in core joomla banner code, especially if it’s this easy to do.
June 17th, 2009 at 9:16 pm
How do I remove the year? so it is only the date ex: 02-06 it is looking at.
I want to use it for an event that happens at the same date every year.
Like a birthday.
June 17th, 2009 at 10:45 pm
Thank you for all of the comments guys, really appreciate them.
For Morten, to limit the banner to show at certain date, you just need to change the $wheres[].
the simplest way will be :
INSTEAD OF putting :
$wheres[] = “(publish_up = ’0000-00-00 00:00:00′ OR publish_up < = CURDATE())";
$wheres[] = "(publish_down = '0000-00-00 00:00:00' OR publish_down >= CURDATE())”;
You will use :
$wheres[] = “MONTH(publish_up) = MONTH(CURDATE()) AND DAYOFMONTH(publish_up) = DAYOFMONTH(CURDATE())”;
in this case you will keep entering the year in admin, but it will be ignored. I haven’t test this yet, so yeah give it a go. Cheers.
June 30th, 2009 at 8:47 pm
Thanks for the replay… but I can’t get to work…
June 30th, 2009 at 8:49 pm
Sorry… it works… nice
June 30th, 2009 at 8:54 pm
Great
hope it helps… Share the “giving” lifestyle 
You can post other questions if you face other difficulties with Joomla, or if you need my professional service to develop Joomla module/component
July 13th, 2009 at 7:53 am
For some reason this file doesn’t exist on my server:
\components\com_banners\models\banner.php
Do you have any suggestions? Thanks!
July 13th, 2009 at 8:06 am
Nevermind
I just found the file banner/php. This hack is working perfectly. I’ve been searching for this feature for a long time. Thank YOU!
October 28th, 2009 at 3:59 pm
Fabuleux,
Thanks a lot mate, you did a great job !
November 26th, 2009 at 11:45 pm
Now, that’s what I call clean’n'simple. Works like a charm, thanks dude!
Bo Dudek
Webdeveloper
Denmark
January 15th, 2010 at 5:53 pm
Hi,
Thank you for this code. I am happy to use this code. Thank you sooooooooooooooooooooooooooooooooooooooooooooooooooooooo………. 1000 times
March 26th, 2010 at 11:09 pm
Hi,
I have just detected this option. absolutely great!
Thank you very much.
pat
May 11th, 2010 at 4:39 am
I do not have the \components\com_banners\models\banner.php file on my system. no ‘models’ directory at all.
Any help?
May 11th, 2010 at 5:12 am
DOH! … nevermind, I found it. Thanks for a great hack!
August 2nd, 2010 at 5:24 pm
This is interesting, I don’t know if a new or modified Joomla 1.5 Ad. comp. ot module/plugin is now available to do this. Is there one?
Is it possible to have a feature where a given email is sent by the system when say the clients Ad. is one month from “renewal”?
January 13th, 2011 at 2:18 am
Gr8 mod! I was looking for it for a while. But i was searching for something with date and time to start or stop
I made a little variation of yours. Now i can set publish and end to a specific date and time
! Thx for your work. If you want, contact me, and i will send you my version 
Cheers!
February 12th, 2011 at 6:24 pm
I made these changes but it doesn’t work for me. The module reverts back to unlimited impressions and the banners continue to show after I set a stop date. I eneter stop dates for all the banners and when I checked a few months later all the banners had reverted to unlimited impressions. Can you help
March 22nd, 2011 at 9:25 pm
I’m having the same problem as Jill – it used to work, but ever since I updated to 1.5.15 (not even the latest version) the hack doesn’t work and the banners are running past their end dates. Any answers? Really loved it when it worked though
March 28th, 2011 at 3:22 am
So many sites and now I can thank you for making my life easier. Much Appreciated
May 24th, 2011 at 2:46 am
allo
very good
how to create tag to place a banner in article ?
thanks to answers
June 3rd, 2011 at 6:51 pm
I’ve always wondered why Joomla has a start and endate in the banners database table, but doesn’t use it. While it’s so easy to implement in the interface.
June 7th, 2011 at 5:34 am
First I would like to thank the solution presented.
Almost fully met my needs (and many others, I’m sure).
Want more tips on how to use a field in the full format of Joomla, with the date and time.
Again thanks,
Hugs.
June 24th, 2011 at 7:17 pm
Thanks a lot, very useful. Is there any way how tu unpublish banner after expiration date? Any tips how to do it? Anyway, thanks.
June 24th, 2011 at 8:15 pm
Gr8 help provided…worked perfect for me. It will help those who r not much into coding, still want to develop site in joomla. Thanks.
July 21st, 2011 at 1:25 am
This is a perfect solution. I manage websites for a radio station and they currently sell banner ads by run date. Thank you thank you.
September 7th, 2011 at 4:20 pm
thank you very much
:):)
September 18th, 2011 at 7:26 am
Hi, this is a great hack. Must be in the Joomla core features!
I made some little changes to publish banners for one day:
publish_up , ‘publish_up’, ‘publish_up’, ‘%Y-%m-%d 00:00:00′, array(‘class’=>’inputbox’, ‘size’=>’25′, ‘maxlength’=>’19′)); ?>
publish_down , ‘publish_down’, ‘publish_down’, ‘%Y-%m-%d 23:59:59′, array(‘class’=>’inputbox’, ‘size’=>’25′, ‘maxlength’=>’19′)); ?>
AND
$wheres[] = “(publish_up = ’0000-00-00 00:00:00′ OR publish_up = NOW())”;
Thanks!
September 28th, 2011 at 1:12 pm
Great hack man…life savor…now I don’t have to deal with bulky components. This is exactly what I needed…
October 6th, 2011 at 4:02 am
It’s really great. thanks
October 29th, 2011 at 1:20 pm
Wow…Amazing pal. this is exactly what i need. all d best for u future jobs, but we are expecting more than this from you, this is our kindly request..
October 29th, 2011 at 1:27 pm
am struggling with joomla1.5 blog component (lyften bloggie) can you slove my problem (there is no option for reply the comment ) thanks in advance
November 1st, 2011 at 12:05 am
That is great but since it is now core feature of Joomla 1.6 , we need one step further.
How can we make banners “rotate” on based of time and/or day of week
That would be really helpful
November 15th, 2011 at 6:39 pm
thanks mate!
November 15th, 2011 at 11:30 pm
great hack, tnx so much!
December 21st, 2011 at 3:29 am
Any way to make this literally unpublish the banner after the end date?
Thanks,
Max